Fork Copy int kt; Socket sk = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); IPEndPoint serverInfo = new IPEndPoint(IPAddress.Any, 9000); sk.Bind(serverInfo); IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0); EndPoint Remote = (EndPoint)(sender); byte[] dl = new byte[1024]; Console.WriteLine("Waiting"); kt = sk.ReceiveFrom(dl, ref Remote); Console.WriteLine(getString(dl, 0, kt)); string s = "Connected"; dl = getByte(s); sk.SendTo(dl, dl.Length, SocketFlags.None, Remote); while (true) { //nhan du lieu try { dl = new byte[1024]; kt = sk.ReceiveFrom(dl, ref Remote); } catch (IOException e) { Console.WriteLine("CANNOT RECEIVE DATA"); Console.ReadLine(); break; } s = getString(dl, 0, kt); if (s.Length == 0) { break; } //convert string[] arr = s.Split(' '); float sum = 0; foreach(string a in arr) { float f = float.Parse(a); sum += f; } dl = getByte("Length: " + arr.Length + ", Sum: " + sum); sk.SendTo(dl, dl.Length, SocketFlags.None, Remote); log(s); } public static string getString(byte[] b, int offset, int length) { return Encoding.ASCII.GetString(b, offset, length); } public static byte[] getByte(string s) { return Encoding.ASCII.GetBytes(s); }