static void Main(string[] args) { // IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 9050); UdpClient newsock = new UdpClient(9050); IPEndPoint send = new IPEndPoint(IPAddress.Any, 0); byte[] data1 = newsock.Receive(ref send); string data = Encoding.ASCII.GetString(data1); Console.WriteLine("Client {0}:{1}\n",send.Port.ToString(),data); receiver rs = new receiver(send,newsock); ThreadStart ts = new ThreadStart(rs.receive); Thread t = new Thread(ts); t.Start(); while(true) { UdpClient up = new UdpClient(send.Address.ToString(), send.Port); Console.Write("Server:"); string s = Console.ReadLine(); byte[] s1 = Encoding.ASCII.GetBytes(s); int n = up.Send(s1, s1.Length); } }
static void Main(string[] args) { // IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 9050); UdpClient newsock = new UdpClient(9050); IPEndPoint send = new IPEndPoint(IPAddress.Any, 0); byte[] data1 = newsock.Receive(ref send); string data = Encoding.ASCII.GetString(data1); Console.WriteLine("Client {0}:{1}\n", send.Port.ToString(), data); receiver rs = new receiver(send, newsock); ThreadStart ts = new ThreadStart(rs.receive); Thread t = new Thread(ts); t.Start(); while (true) { UdpClient up = new UdpClient(send.Address.ToString(), send.Port); Console.Write("Server:"); string s = Console.ReadLine(); byte[] s1 = Encoding.ASCII.GetBytes(s); int n = up.Send(s1, s1.Length); } }