0

Possible Duplicate:
TCP Client Side Issue

I am having a big trouble by using c# TCP client and server application. Everything work fine... But in some case, when a TCP server send simultaneous response to TCP client, The client can consider both of the two message send by the server are actually a single message. I don't know why such case are occurring... If any one know please help me. My TCP client and Server are written in c#.

Community
  • 1
  • 1
Hope
  • 1,252
  • 4
  • 17
  • 35

2 Answers2

0

This is normal behavior for TCP. It guarantees you the sequence (if the server sends A, then B, client will never receive B, then A), but it knows nothing about your "messages".

To break data into messages at client side, you need some application protocol over TCP. E.g., HTTP uses CRLFCRLF to determine the end of the HTTP message.
You may use existing one or made your own, depending on your needs.

Dennis
  • 37,026
  • 10
  • 82
  • 150
0

There's no guarantee of a 1-1 correspondence between calls of Write on one end of a TCP connection, and calls to Read on the other end. You may receive no data, part of a message, an entire message, or multiple messages for each call to Read

It is up to you to perform any appropriate work to turn these blobs of data back into messages - or to switch to a higher level technology (e.g. WCF) if you want something else to do the hard work.

Damien_The_Unbeliever
  • 234,701
  • 27
  • 340
  • 448