private void btnGetMsg_Click(object sender, EventArgs e) { IPHostEntry ipHostInfo = Dns.Resolve("192.168.1.6"); IPAddress ipAddress = ipHostInfo.AddressList[0]; IPEndPoint remoteEP = new IPEndPoint(ipAddress, 1000); TcpClient c = new TcpClient(remoteEP); int aa = c.ReceiveBufferSize; NetworkStream ns = c.GetStream(); //get stream byte[] buf = new byte[100]; //create byte array to receive data ns.Read(buf, 0, 100); // read data from stream into byte array string st = System.Text.Encoding.ASCII.GetString(buf); // convert byte array to string if (st != "") { listBox1.Items.Add(string.Concat("Server Said: ", st)); } }
private void button2_Click(object sender, EventArgs e) { TcpListener l = new TcpListener(1000); l.Start(); // start listener TcpClient c = l.AcceptTcpClient(); // wait for client to make request NetworkStream ns = c.GetStream(); // access steam to send data to client. string st = textBox1.Text; // get system date and convert it to string listBox1.Items.Add(string.Concat("Server Said: ", textBox1.Text)); byte[] buf = System.Text.Encoding.ASCII.GetBytes(st); // convert string to an array of bytes ns.Write(buf, 0, st.Length); // write to stream l.Stop(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)