private void ShowUDPClientView() { UDPClientModel p1 = (UDPClientModel)socketModels[status.index1]; UdpClientSocketObject p2 = (UdpClientSocketObject)p1.Children[status.index2]; TLremoteIP.Visibility = Visibility.Visible; TremoteIP.Visibility = Visibility.Visible; TLremotePort.Visibility = Visibility.Visible; TremotePort.Visibility = Visibility.Visible; TLlocalPort.Visibility = Visibility.Visible; TlocalPort.Visibility = Visibility.Visible; TremoteIP.Text = p2.remoteIpEP.Address.ToString(); TremotePort.Text = p2.remoteIpEP.Port.ToString(); TlocalPort.Text = ((IPEndPoint)p2.socket.LocalEndPoint).Port.ToString(); }
public int CreateSocket(IPEndPoint remoteIpEP, int localPort) { Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); try { socket.Bind(new IPEndPoint(IPAddress.Any, localPort)); } catch (Exception) { return(-1); } socket.EnableBroadcast = true; UdpClientSocketObject socketObj = new UdpClientSocketObject(); socketObj.socket = socket; socketObj.Children = null; // 不显示隐藏的3级节点 socketObj.remoteIpEP = remoteIpEP; socketObj.DisplayName = GetDisplayName(socketObj.remoteIpEP); socketObj.Parent = this; socketObjs.Add(socketObj); AsynchronousSocketListener.StartRead(socketObj); return(0); }