read TCP stream issue
Hi,
Maybe you will be able to give me some tips 😅
I am writting a tool using already created API. The creator of the api doesn't know c# so he isn't able to help me with that issue (API is written in C++ but it should work fine with c# too).
In short - tool sends json messages using TCP socket. Messages are terminated with '\1' character or 0x01 byte (so one "packet" can in fact be stored in 2 <or more> messages received from a bot).
and this is the part I have no idea how to handle.
I wrote something like that:
but it's not reading packets which are stored in more than one tcp message.
do you have any ideas how can I fix that?
I made a tool with QT and c++..and ok. it works fine. but I personally hate c++ and "upgrading" this tool is a horror for me.
With C# it seems to be not reading part of the messages, which should be handled. I checked that and seems to be missing about 30% of the packets.
There is no official c# api...but this kind of api should be possible to work with any language which supports JSON and TCP sockets.
thanks for any tip in advance and have a nice day!
5 Replies
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
see $pipeline
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
(Contains example for Socket
TCP Echo
)
https://devblogs.microsoft.com/dotnet/system-io-pipelines-high-performance-io-in-net/
https://docs.microsoft.com/en-us/dotnet/standard/io/pipelines
if you're handling data from/to a stream, and dealing with intermediate buffer / parser / writer, you probably should consider using System.IO.Pipelines
It's handling internally
* temporary buffer
* memory pool to re-use memory and avoid allocation
* accumulate buffer until you decide you have enough data to do something (deserialize ?)
There's dedicated extensions for Stream
for specific use case like :
(Contains a sample to read file / dump to console)
Reading (eg: to a file):
Writing (eg: to Console):
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View