private void Hole(IPEndPoint iPEndPoint, byte[] buffer) { if (iPEndPoint.CString() == Remote.CString()) { //返回的IP var ip = System.Text.Encoding.UTF8.GetString(buffer); Console.WriteLine(iPEndPoint + " " + ip); var arr = ip.Split(':'); IPEndPoint remote = new IPEndPoint(IPAddress.Parse(arr[0]), Convert.ToInt32(arr[1])); //先接收 UdpClient.BeginReceive((aarr) => { IPEndPoint temp = null; var fialResult = UdpClient.EndReceive(aarr, ref temp); if (fialResult.Length == 113) { IsAvailable = true; Console.WriteLine("打通"); Remote = remote; InitTask(); } }, null); var start = new byte[112]; //顺着通道建立连接 UdpClient.Send(start, start.Length, remote); } else { UdpClient.BeginReceive(WaitForEnd, null); } }