Share via


Simple .NET TCP Framing Example

Recently, Jon Cole from the System.Net QA team posted a great article in response to questions we've received on our .Net Networking Forum (https://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=40&SiteID=1).  His post can be found here:  https://blogs.msdn.com/joncole/archive/2006/03/20/555721.aspx

Excerpt from the article:

A common misunderstanding for developers new to network programming over TCP sockets is how messages are sent and received.  I frequently hear the statement that "my data is not arriving on the other side of the socket in the same format that I sent it."  The most common cause of this is because the TCP protocol does not guarantee that it will keep message boundaries.  In other words, you could send "Hello World" in a single call to Send(), but the other side of the socket stream may have to do multiple Receive() calls on the socket to get all of the data (the first Receive might return "he" and the second "llo world").  ........

-- Mike Flasko

Comments

  • Anonymous
    April 06, 2006
    Debugging the ASP.NET worker process running at
    100% [Via: scott@hanselman.com (Scott
    Hanselman)...
  • Anonymous
    April 08, 2006
    If you send "Hello World" and receive "he" + "llo world" then you have not a TCP socket.  For TCP one should have received "He" + "llo World". Please, pay attention when working with these,as some novices will understand really bad things