1

I want to send message from PC1 to PC2 via TCP socket. The question is, how can I tell the message received at PC2 is partial or complete? Or more specific, how to determine the start and end of a TCP message?

1) Add message length information at the start of a TCP message?

2) Add special flag bytes to the start and end of a TCP message?

Jedi
  • 882
  • 1
  • 8
  • 24

1 Answers1

1

Yes, or

(3) use a self-describing protocol like XML, or

(4) a type-length-value protocol, or

(5) a self-implementing protocol like XDR, or

(6) ...

Note that if you use start/end bytes like STX/ETX, you need to escape them when they occur in the middle of a message, and you also need to escape the escape.

user207421
  • 305,947
  • 44
  • 307
  • 483