title: .NET TCP socket with session
body: <p>Is there any way of dealing with sessions with sockets in C#?</p>
  
  <p>Example of my problem:<br>
  I have a server with a socket listening on port 5672.  </p>
  
  <pre><code>TcpListener socket = new TcpListener(localAddr, 5672);  
  socket.Start();  
  Console.Write("Waiting for a connection... ");  
  
  // Perform a blocking call to accept requests.  
  TcpClient client = socket.AcceptTcpClient();  
  Console.WriteLine("Connected to client!");
  </code></pre>
  
  <p>And i have two clients that will send one byte. Client A send 0x1 and client B send 0x2.
  From the server side, i read this data like this:  </p>
  
  <pre><code>Byte[] bytes = new Byte[256];
  String data = null;
  
  NetworkStream stream = client.GetStream();
  while ((stream.Read(bytes, 0, bytes.Length)) != 0)
  {
       byte[] answer = new ...
       stream.Write(answer , 0, answer.Length);
  }  
  </code></pre>
  
  <p>Then client A sends 0x11.
  I need a way to know that this client is the same that sent "0x1" before.</p>