NetCoreServer icon indicating copy to clipboard operation
NetCoreServer copied to clipboard

Corrupted received data

Open Fantoom opened this issue 4 years ago • 2 comments

I am wrapping string data in object (id and data) and serializing it to json , and when I am trying to send big data, in other side I get only 8192 bytes and corrupted json string. How can I fix that?

I tried to find where the data is separating, but didn't find it. Can I wrap it in object after data will have been separated?

Fantoom avatar May 01 '20 13:05 Fantoom

NetCoreServer use stream protocol model. All data send into stream and we only guarantee the order of send/received bytes in stream, but messages/objects could be spited. To overcome this you have to create top level message protocol. The simple idea of it is to send message size in first 4 bytes and then message body. On receive side read 4 bytes as a message size and then collect message data of the size. And only then deserialize data into object and process it.

chronoxor avatar May 01 '20 22:05 chronoxor

One reason I love your NetCoreServer is its ability to be the foundation for engineers to learn more about OSI layer 5, 6 and 7 in situations as described above.

polarapfel avatar Sep 05 '20 05:09 polarapfel

@chronoxor How can i read exact byte count from session? I need to disable receive buffer.

furkangkhsn avatar Aug 15 '22 12:08 furkangkhsn