C# streaming sockets, how to separate messages?

后端 未结 6 1635
谎友^
谎友^ 2021-01-15 06:40

Kinda long title, but anyways...

I\'ve been looking at these examples, specifically on the parts on writing and reading the size of the message to the byte streams

6条回答
  •  时光取名叫无心
    2021-01-15 07:47

    Use WriteLine instead of Write, ReadLine instead of Read...

    If you are talking sending pure textual messages, append the Newline character at the end of your messages. Then, read bytes till you encounter this Newline character and convert the bytes into a string. For your convenience, any System.IO.StreamReader and System.IO.StreamReader implement this behavior in a single method (WriterLine or ReadLine) writer.WriteLine("Line to send"); string lineSent = reader.ReadLine();

提交回复
热议问题