title: C# client-server protocol/model question
body: <p>I am trying to conceptually work through a model for a client-server socket application I am writing in c# (both client and server).  My server will need to handle many clients at once, and preferably  multiple requests from a client at once.  I have worked out a container for my communication where I will send a fixed length header at the beginning of each message which will contain (among other things) the length of the message.  I have some experience with socket programming in c#, so I am comfortable using Asynchronous sockets.  </p>
  
  <p>The main thing I am having trouble with, conceptually, is I need both the client and server to be able to receive messages at any time.  The client will establish a connection, and remain "logged in" (like an IM client), and it will need to both receive data at arbitrary times and make requests at arbitrary times.  I had also wanted, as part of my protocol, to receive a response to each request made (be it from the server to client, or client to server).  </p>
  
  <p>I would like to be able to use a single socket if possible.  I believe I could make this work using two sockets, one for making server->client requests and one for client->server requests, but I don't want the extra complications of dealing with two ports/connections.  However, using a single socket, I am not sure how to manage sending requests and getting responses when they could be interleaved.</p>
  
  <p>I cannot find any examples of a similar server or client in my searching.  Thanks to anyone who offers any ides.</p>