Python Forum

Full Version: Sending/Receiving Multiple Message from Server or Client
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, my problem is that I don't know how I can send two times send and receive message from client to server.
I've coded these;
Example
# Server Side
ip=""
port=8888
buffersize=1024

s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((myIP, myPort)) 
s.listen(1)
(cl, adress) = s.accept()

cl.send("hi!".encoded())

msg=cl.recv(bufferSize).decode()
msg=msg[0]
print(" Received message is '{}'".format(msg))
# Client Side
ip=""
port=8888


s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(ip,port)

msg=s.recv(1024).decode()
print(" {} ".format(msg))

#sending to server
s.send("OK!".encode())
This codes work well. They can communicate with each other.
But, I want to send second message and I want to receive second message in a loop.
How can we coded this?

Best Regard...