I have this simple server script. My objective for this script is :
- Wait for a client connection
- Receive massages from client until the client disconnect
- Once client disconnect, wait for another client to connect
- Receive massages until the client disconnect
- Repeat...
import socket
server_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
server_socket.bind(("",5000))
server_socket.listen(5)
print "Awaiting Client connection"
client_socket, address =server_socket.accept()
print "Connection established.. with ",address
while True:
data=client_socket.recv(512)
if not data:
client_socket.close()
print "Client disconnected, Awaiting new connections..."
client_socket, address =server_socket.accept()
print "Connection from ",address
else:
print "RECIEVED:",data
My Question is even though the script seems to be working when i test it on a pair of pc, i noticed that after it received the connection from the client, that is line no 7
print "Connection established.. with ",address
the python shell window seems unresponsive (become not responding if i try to move the shell window) until the client send any message.
As far as i understand, if there is no incoming message from client, client_socket.recv(512) will just wait for the data from the client.
But why it became unresponsive? To make things clearer,
-the script works just fine ( it receive data and print it out from screen & wait for the new connection if client disconnect)
-the cursor in console windows stop blinking
-when i try to move the console window around , it become unresponsive and windows give me a message "this program has stopped responding"
recvmethod is blocking - see stackoverflow.com/questions/9770567/….