title: Is there any message-based TCP socket library in .NET?
body: <p>While I'm a newbie in socket programming, as I was writing a simple tcp server-client program, I found the stream-based api is not that convenient to use.</p>
  
  <p>My program is simply simple: </p>
  
  <ol>
  <li>The client connects to a server</li>
  <li>The server continuously send messages to client, in a unexpectable interval</li>
  <li>The client receives message and do work according to the data contained in message</li>
  </ol>
  
  <p>However, using the stream-based api, I have to:</p>
  
  <ul>
  <li>Define a <strong>message delimiter / separator</strong></li>
  <li>Use a <code>while</code> loop to read data from stream</li>
  <li>Concat all bytes, try to find the <strong>delimiter</strong></li>
  <li>If <strong>delimiter</strong> exists, split the data, extract the message</li>
  </ul>
  
  <p>That's a lot work, even more than the entire logic of my program, so I'm wondering is there a library could do stuffs above for me, with such library I can program like this:</p>
  
  <pre><code>// Server
  TcpListenerEx server = new TcpListenerEx();
  TcpClientEx client = server.Accept();
  client.SendMessage(new StringMessage("hello world"));
  
  // Client
  TcpClientEx client = new TcpClientEx();
  client.Connect("localhost", 8989);
  while (true) {
      IMessage message = client.ReadMesage();
      // Do work acording to message
  }
  </code></pre>
  
  <p>Any suggestion would be welcome, thanks.</p>