Reputation: 5836
Newbie question here.. Just trying to be sure here..
This is not a HTTP Keep-Alive question.
Is there a way to make sure a socket gets closed() after a certain amount of time.
Why i'm asking this because if I just close socket right away.. the client may not receive the packet to indicate like incorrect password etc..
Is there any timeout like built in command inside Socket?
I'm trying to avoid building a timer or event to close it off thinking of a alternate solution
Upvotes: 3
Views: 4513
Reputation: 7411
I assume that you are talking about the TCP protocol.
If you want to make sure that something has been received by the client, then the client needs to send a response for the last received message (e.g. bad password) and the server closes the connection after receiving the confirmation or when there was a readtimeout.
Upvotes: 0
Reputation: 78507
I never tried it myself, but there is LingerOption
.
Take a look at Socket.LingerState Property.
This property controls the length of time that a connection-oriented connection will remain open after a call to Close when data remains to be sent. When you call methods to send data to a peer, this data is placed in the outgoing network buffer. This property can be used to ensure that this data is sent to the remote host before the Close method drops the connection.
Upvotes: 2