Chat Program two way communication | Socket Programming in Python
import socket
server_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
LOCALHOST = '127.0.0.1'
port = 9990
server_socket.bind((LOCALHOST,port))
server_socket.listen(5)
print("Server started...")
client_sockets,addr=server_socket.accept()
while True:
msg_received = client_sockets.recv(1024)
msg_received = msg_received.decode()
print("Client:", msg_received)
msg_send = input("Me:")
client_sockets.send(msg_send.encode("ascii"))
client_sockets.close()
import socket
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
LOCALHOST = '127.0.0.1'
port = 9990
s.connect((LOCALHOST,port))
print("New client created:")
while True:
client_message = input("Me: ")
s.send(client_message.encode())
msg_received = s.recv(1024)
msg_received = msg_received.decode()
print("Server:",msg_received)
if msg_received == 'exit':
break;
s.close()
#pythonAssignmentHelp #PythonGuiHelp #PythonNetworkProgramming #pythonMongoDBAssignmentHelp