Name
Socket
Synopsis
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.
You can interrogate the socket to determine if it supports IPv4
(standard TCP/IP quad-style addresses) by examining the
SupportsIPV4
property; similarly, you can
determine if the socket supports IPv6 by examining
SupportsIPv6
.
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 ...
Get C# in a Nutshell, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.