CHAT
CHAT
import socket
import sys
import time
s=socket.socket()
host=socket.gethostname()
print("server will start on host:",host)
print("")
port=8080
s.bind((host,port))
print("server done binding to the host and port successfully")
print("")
print("server is waiting for incomming connections")
print("")
s.listen(3)
conn,addr=s.accept()
print(addr,"is connected to the server and now online")
while 1:
message=input(str(">>"))
message=message.encode()
conn.send(message)
print("message has been sent...")
incomming_message=conn.recv(1024)
incomming_message=incomming_message.decode()
print("server : ",incomming_message)
import socket
import sys
import time
s=socket.socket()
host=input(str("enter the hostname of the server:"))
port=8080
s.connect((host,port))
print("connected to server")
while 1:
incomming_message=s.recv(1024)
incomming_message=incomming_message.decode()
print("server : ",incomming_message)
print("")
message=input(str(">>"))
message=message.encode()
s.send(message)
print("message has been sent...")
OUTPUT:
Chat_server:
Client server: