I have a typical network protocol consisting of typical message stream (32-bit length field + variable-length body) and I want to read messages asynchronously from a TCP socket.
However C# seems to provide a rather low-level API: I still have to allocate buffers, track the written offset and data length by hand, and maintain state between separate calls to read length and body like in the bad old days of C.
Are there any higher-level functions that I can try out before diving into writing tedious asynchronous stateful code? (no third-party libraries).
Java supports the following three types of sockets: Stream Sockets. Datagram Sockets. Raw Sockets.
Sockets allow you to exchange information between processes on the same machine or across a network, distribute work to the most efficient machine, and they easily allow access to centralized data. Socket application program interfaces (APIs) are the network standard for TCP/IP.
Nothing built-in, no. In fact I can't think of any 3rd party libs for this either. I haven't tried, but it occurs that C# 5 may offer some language-level shiny here. The other option is to use a separate thread that reads synchronously, but that then uses a thread instead of IO completion ports.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With