On Apr 8, 11:33   
>  
>       
>    
I can't explain why Ruby or the socket API does not throw an error in
all cases. I have tested a bit with various combinations and there
appear to be factors that make the outcome appear somewhat random.
Sometimes i get ECONNRESET, sometimes ECONNABORT, and sometimes recv
simply return an empty string.

I noticed that you use 'read' and 'write' in your example. This puts
the socket into buffered mode. The application may read more data than
your script has read, and hence the buffer in the OS is empty. Simply
converting to 'recv' and 'send' may improve your case, but and error
on 'send' is still not guaranteed.

If you are very worried about data getting delivered, I suggest using
this method from the Winsock FAQ [1]:

1. Finish sending data.
2. Call shutdown() with the how parameter set to 1. (Socket#shutdown)
3. Loop on recv() until it returns 0. (Empty string in Ruby)
4. Call closesocket(). (Socket#close)

This way, recv() will throw an error if there is *unacknowledged*
data. If you employ the same method on the server, recv() will give
you all the data that the client has sent.

[1] http://tangentsoft.net/wskfaq/newbie.html#howclose

Lars