TcpClient client = new TcpClient(); client.BeginConnect("127.0.0.1", 12345, ConnectCallback, client); private static void ConnectCallback(IAsyncResult ar) { TcpClient client = (TcpClient)ar.AsyncState; client.EndConnect(ar); Console.WriteLine("Connected to server"); }This code creates a TcpClient object and connects to the server with IP address "127.0.0.1" and port number 12345. The ConnectCallback method is called when the connection is established, and it prints "Connected to server" to the console. Package Library: The TcpClient class is present in the System.Net.Sockets namespace of the .NET framework.