Advice sought on command response type app

Joined
Mar 26, 2009
Messages
15
Programming Experience
Beginner
I'm trying to develop a client server app to facilitate the transfer of data between PCs over TCP/IP.

I'm using the .Net sockets class and using asynchronous methods. I have a simple app going whereby a client can send a message to the the server and it will echo the message back to the client. The server can also send messages to the clients.

However my real world app is a bit more complicated. In pseudocode the process is as follows:

1. Client attempts to connect.
2. Server accepts connection and sends a msg to client requesting an ID (for example).
3. Client receives msg and sends back ID.
4. Server receives msg and checks the ID (against DB for example) and sends back a msg to say that access is granted or denied.
5. If access is granted the client sends a msg to the server requesting data. If denied the connection is ended.
6. Server receives request for data msg and sends a line of data.
7. Client receives line of data, and processes it. Once processed it sends back an OK.
8. If an OK is received the server sends another line of data and the process continues until there is no data (at which point the connection is ended).

An advantage of asynchronous methods is that it allows multiple clients to connect in a non blocking fashion, however I'm not sure how on the server I can keep track of where I am in the chain for each client. In the example above the sequence applies to a single client from beginning to end but in the real world I could have a second client connecting in the middle of the above process and I'm wondering how do keep track of things.

Also when I send a message I'd like not to leave it to chance that it was received at the other end. Is there some way of triggering a timeout so that I can end the connection if I dont get a response within a defined period. I think I can get it going on the client using the timer class but I'm not sure how to implement timeouts when dealing with multiple clients on the server end.

Any suggestions would be welcome. Sorry about the lack of specifics - I'm still at the stage of trying to get my head around the larger picture on how I should structure things.
 
Back
Top