I am creating a simple server (C#) and client (python) that communicate using sockets.
The server create a
var listener = new Socket(AddressFamily.InterNetwork,SocketType.Stream, ProtocolType.Tcp)
then binds, listens in a infinite loop
while (true)
{// Set the event to nonsignaled state.AllDone.Reset();// Start an asynchronous socket to listen for connections.Console.WriteLine("Waiting for a connection...");listener.BeginAccept(AcceptCallback, listener);// Wait until a connection is made before continuing.AllDone.WaitOne();
}
the AcceptCallback
calls BeginReceive whose callbackk reads the buffer and sends back a message to the client
everything works. Client sends a message, server sees it, replies, client sees it. But when the client tries to send a message again (for testing client is in a loop), nothing happens
the python client:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((host, port))
while True:sock.sendall(data)blockLen = sock.recv(32) #server sends back a string prefixed with how long the string isserverReply = sock.recv(blockLen)
how do i keep the socket from dying?