日期:2014-05-17 浏览次数:20467 次
protected void Page_Load(object sender, EventArgs e) { Socket sock60 = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); //设置SOCKET允许多个SOCKET访问同一个本地IP地址和端口号 sock60.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1); IPEndPoint iep60 = new IPEndPoint(IPAddress.Any, 5860); sock60.Bind(iep60); //绑定IP/端口 EndPoint ep = (EndPoint)iep60; byte[] data = new byte[1024]; int recv = sock60.ReceiveFrom(data, ref ep); //接受数据 string stringData = Encoding.UTF8.GetString(data, 0, recv); //接收端口发送的String Label1.Text = stringData; }