This class implements a standard Berkeley socket. Each socket is constructed with the address family to use, the socket type (datagram or stream), and the protocol that the socket will use. Every socket must be bound to a local endpoint before you can use it. The Bind() method takes a System.Net.IPEndPoint object that contains the local IP address and port number to bind the socket to. Bind() must be called before any connection can be made through the socket. To establish a connection to a remote address, use Connect().

To listen for connections from remote clients, use Listen() to set the socket in listening mode where it waits for incoming connections. The integer argument to Listen() specifies how many remote connection requests can be queued at one time, waiting for a socket connection. A call to Accept() returns a new socket that connects to the first pending connection request in the listening queue. This new socket exists only for this connection and is destroyed once the connection is closed.

Data is written to a socket using Send(). Data from a specified buffer is sent through the socket to its remote endpoint. Data is read from a socket using Receive(). Receive() gets data from the socket connection and stores it in a specified receive buffer.

You can set several socket options to control the behavior of a socket with SetSocketOption(). This method requires a SocketOptionLevel value, which determines the type of socket option to set. For example, ...

Get VB.NET Core Classes in a Nutshell now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.