TCPSocket drops connection after reply

Every time I have used a TCPSocket before I have been writing a client app. My current project has both a client and a server and the connection is always dropped right after the server replies. I don’t know how to tell which end is dropping the connection but I suspect it has something to do with the timing between the server’s write and its beginning to listen.

soc.write(result) while soc.BytesToSend > 0 app.DoEvents // server is a console app wend soc.Listen
I have code in the client’s socket error event that prints the error and it fires at the same time that the result (answer received from server) is written to the screen.

TCPSocket.Listen should reset the socket and wait for a new connection. I don’t think that’s what you intend there.

Just out of curiosity, why aren’t you using a ServerSocket?

I never considered it. After reading about it, it looks like it is exactly what I need. Thanks.