Microsoft .NET Socket API Implementation
System.Net.Sockets
- The System.Net.Sockets.Socket class is an implementation of the Berkeley Sockets API in the .NET framework.
- In addition to the standard Berkeley Socket functions, it also features methods for asynchronous sending and receiving of data.
List of Commonly Used Methods in the Socket Class
Socket() (Constructor)
Bind()
Listen()
Accept()
Connect()
Send()
Receive()
Shutdown()
Close()
Commonly Used Asynchronous Methods in the Socket Class
AcceptAsync(), BeginAccept(), and EndAccept()
SendAsync(), BeginSend(), and EndSend()
ReceiveAsync(), BeginReceive(), and EndReceive()
Asynchronous methods are helpful when you do not want your application to block while waiting for operations such as sending and receiving to complete. These are useful for programs that are event-driven or user-facing such as Windows Forms apps.
When using the asynchronous methods, you may no longer need to set the Blocking mode of the socket to false.
The *Async versions of the methods are used if you prefer to code using the Task-based asynchronous pattern (TAP) which is a style of programming asynchronous code.
The Begin* and End* versions can be used if you prefer to code using the more traditional APM pattern.
Commonly Used Properties of the Socket Class
Available
Gets the amount of data that has been received from the network and is available to be read.
Blocking
Gets or sets the blocking mode of the socket. true by default.
Connected
Is true if the socket is connected.
DontFragment
Used if you don't want the packets to be fragmented.
RemoteEndPoint
Allows you to get the IP address and port you are connected to on the other end.
Ttl
Gets or sets a value that specifies the Time To Live (TTL) value of Internet Protocol (IP) packets sent by the Socket.
Source: https://docs.microsoft.com/en-us/dotnet/api/system.net.sockets.socket?view=netframework-4.8