Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Higher-level socket functions

Tags:

c#

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).

like image 419
Alex B Avatar asked Feb 22 '11 06:02

Alex B


People also ask

What are the three types of socket function?

Java supports the following three types of sockets: Stream Sockets. Datagram Sockets. Raw Sockets.

What is the function of a 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.


1 Answers

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.

like image 146
Marc Gravell Avatar answered Nov 15 '22 21:11

Marc Gravell