using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.Net.Sockets; using System.IO; namespace tcpclientexample { class Program { static void Main(string[] args) { try { TcpClient tcpClient = new TcpClient(); Console.WriteLine("Connecting...."); tcpClient.Connect("127.0.0.1", 8888); Console.WriteLine("Connected"); Console.Write("Enter the string to be transmitted: "); String str = Console.ReadLine(); Stream stm = tcpClient.GetStream(); ASCIIEncoding asen = new ASCIIEncoding(); byte[] ba = asen.GetBytes(str); Console.WriteLine("Transmitting...."); stm.Write(ba, 0, ba.Length); byte[] bb = new byte[100]; int k = stm.Read(bb, 0, 100); for (int i = 0; i < k; i++) { Console.Write(Convert.ToChar(bb[i])); } tcpClient.Close(); } catch (Exception e) { Console.WriteLine("Error: " + e.StackTrace); } } } }