110,538
社区成员
发帖
与我相关
我的任务
分享
byte[] data = new byte[1024];
IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 9050);//定义一网络端点
Socket newsock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);//定义一个Socket
newsock.Bind(ipep);//Socket与本地的一个终结点相关联
IPEndPoint IpEndPoint = new IPEndPoint(IPAddress.Any, 0);//定义要发送的计算机的地址
EndPoint endPoint = (EndPoint)(IpEndPoint);//
this.lbShow.Text = "正在接收......";
int recv = 0;
recv = newsock.ReceiveFrom(data, ref endPoint);//接受数据
txtReceive.Text = Encoding.ASCII.GetString(data);
string strBackMessage = "Link Sucess";//反馈连接成功信息
data = Encoding.ASCII.GetBytes(strBackMessage);
newsock.SendTo(data, data.Length, SocketFlags.None, endPoint);
newsock.Close();