views:

157

answers:

1

Is it necessary to close the connection of a tcplistener or tcpclient after every message received, or is it possible to close it at a later time while it continues to receive data? Is there any major security issue with leaving it open and listening? I know trojans tend to open a listener and leave it open, will my program be detected as such? Its just a simple chat program....

Thanks for the help!

This is in vb.net.

+1  A: 

It depends what the protocol is. If the protocol expects a new connection for each message, then you should close it. (This is like HTTP 1.0.)

If the protocol allows multiple messages to be sent down the same connection, then it's entirely reasonable to leave it open. (This is like HTTP 1.1 and most native database connections.)

I wouldn't expect your connection to be treated with undue suspicion just for keeping open.

Jon Skeet
K. How can I check what the protocol it uses is?
Cyclone
You should know what you're using the socket for - or put the decision back into the hands of your caller, who should know. At some point *some* code has to know what protocol you're talking, and act accordingly.
Jon Skeet
TCP, got it!
Cyclone