I have a piece of custom built web server code. It was written using the evnet module.
It seems to the cut the length of the message when requested from a remote client. But when I use it on the same machine, it seems to deliver the full message. I can’t figure out what the problem could be or how to diagnose it. I tested it using a web browser, curl and nc. It never delivered the full length message when requesting from remote clients.
Here’s a simplified version of my webserver that still exhibits the problem. I am doing this on Ubuntu 11.04 with Python 2.7.1
You are closing the socket immediately after calling
send()to send a bunch of data. If there is data still buffered, it will be thrown away when you close the socket.Instead, you should call
shutdown(SHUT_WR)on the socket to tell the remote end that you are finished sending. This is called a TCP “half-close”. In response, the other end will close its side, and you will get a notification that the socket is no longer readable. Then, and only then, should you close the socket handle.