try { /// Local IP Address. IPAddress ip = IPAddress.Parse("127.0.0.1"); /// Initializes the Listener. TcpListener myListener = new TcpListener(ip, 8001); /// Start Listeneting at the specified port. myListener.Start(); listbox1.Items.Add("The Listener is running on " + myListener.LocalEndpoint); listbox1.Items.Add("Waiting for a connection..."); Socket mySocket = myListener.AcceptSocket(); listbox1.Items.Add("Connection accepted from " + mySocket.RemoteEndPoint); /// Receives Message From Client. byte[] rData = new byte[100]; int k = mySocket.Receive(rData); listbox1.Items.Add("Recieved..."); for (int i = 0; i < k; i++) listbox1.Items.Add(Convert.ToChar(rData[i])); ASCIIEncoding tData = new ASCIIEncoding(); mySocket.Send(tData.GetBytes("response")); listbox1.Items.Add("\nSent Response"); /// Close Connection. mySocket.Close(); myListener.Stop(); } catch { listbox1.Items.Add("You broke something..."); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)