DEV Community

loading...

Discussion on: Looking for a helpful dotnet library

Collapse
keithn profile image
Keith Nicholas

I write lots of of low level protocols over TCP, and .NET Cores standard socket library sounds like all you need.

The general idea is to thinly layer your design so the protocol part is independent of the underlying sockets. I'm not sure what your protocol looks like, but you will likely want some kind of protocol class that manages a statemachine of the protocol. This protocol class just needs to understand ByteStream and a concept of Connection ( you could make something like a IByteStreamConnection )

Then it becomes pretty easy to unit test, you simply look at the details of the protocol create packets of bytes ( you will likely want to make some kind of 'Packet' class for making encoding and decoding of packets easier. Feed the packets of bytes to your protocol, verify the intended result happens ( hard to know exactly what you are doing )

Collapse
katnel20 profile image
Katie Nelson Author

Thank you Keith. I will be using the low level standard library class TCPClient. I'm juggling with the threads for send and receive right now. There is also a requirement for a heartbeat to be sent every minute, so I'll have a timer or two involved.

It looks like the designer of the protocol was a junior developer. A length field is used a lot and it's formatted differently in many places. For instance, a 2 byte length field of value 6 might be 0x00 0x06 in one place and 0x06 0x00 somewhere else. When an Ascii string is sent it gets prepended with a 2 byte length in Ascii! (0x36 0x30)