Message timeout

Joined
Mar 26, 2009
Messages
15
Programming Experience
Beginner
H,

Could someone explain to me how to do the following. I've been battling with this for ages and its driving me nuts.

I have a server app and a client app that communicate via TCP/IP using the sockets class. I'm using Asynchronous methods (i.e. BeginAccept, EndAccept, BeginReceive, EndReceive etc.) for greater scalability etc. I found a demo app that illustrates the asynchronous socket communication (very well) however its a relatively simple chat-type application where messages can be sent either by the client(s) or the server and are displayed at either end. There is no sequencing of messages or timeouts involved (see Asynchronous Socket Programming in C#: Part II - CodeGuru).

In my situation the basic flow (to begin with) is as follows:

1. When a client connects to the server I need to send a msg to the client asking for a username and password.
2. When the client receives this message it should send another message with said details.
3. In turn when the server receives this msg it should return another msg to the client to indicate success or failure.

What I dont know how to do is when I send a msg from the server how to introduce a timeout, i.e. if I dont get a response to this msg in 1 minute then close the connection to that particular client. The timeout must not effect or block other connections and there may be multiple timeouts in operation at any time as multiple clients can connect.

How do you deal with situations where you are effectively waiting for different responses from different clients?
 
Start a timer on one end if the timer ticks before hearing anything back send back the timeout message. Not sure if that will work I am not very learned in TCP/IP stuff. But if you can send a message asking for user password what is to stop you from just using a timer and sending a timeout message if you dont hear back before the 1 minute long tick of the timer control takes place.
 
Back
Top