// create a socket Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); // connect to a remote host socket.Connect("127.0.0.1", 1234); // send and receive data // close the socket socket.Close();In this example, a socket is created and connected to a remote host. After sending and receiving data, the socket is closed using the Close method. Package library: System.Net.Sockets.