How to: Create a Socket
Before you can use a socket to communicate with remote devices, the socket must be initialized with protocol and network address information. The constructor for theclass has parameters that specify the address family, socket type, and protocol type that the socket uses to make connections.
The following example creates a Socket that can be used to communicate on a TCP/IP-based network, such as the Internet.
To use UDP instead of TCP, change the protocol type, as in the following example:
Theenumeration specifies the standard address families used by the Socket class to resolve network addresses (for example, the AddressFamily.InterNetwork member specifies the IP version 4 address family).
Theenumeration specifies the type of socket (for example, the SocketType.Stream member indicates a standard socket for sending and receiving data with flow control).
Theenumeration specifies the network protocol to use when communicating on the Socket (for example, ProtocolType.Tcp indicates that the socket uses TCP; ProtocolType.Udp indicates that the socket uses UDP).
After a Socket is created, it can either initiate a connection to a remote endpoint or receive connections from remote devices.