110,534
社区成员
发帖
与我相关
我的任务
分享
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);//创建套接字,协议类型设为UDP
IPEndPoint iepp_send = new IPEndPoint(IPAddress.Broadcast, 62006);
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast,1);
socket.SendTo(picInforSendFmt[PicSendUsedPr].SendData, iepp_send);
private void ReceiveThread()//线程
{
threadReceive = new Thread(ReceiveMessage);
threadReceive.IsBackground = true;
threadReceive.Start();
}
private void ReceiveMessage() //UDP接受
{
//绑定主机(地址设为IPAddress.Any)
int port = 62006;
IPEndPoint iep = new IPEndPoint(IPAddress.Any, port);
EndPoint ep = iep as EndPoint;
socket.Bind(ep);
while (true)
{
byte[] bArray = new byte[1024];
socket.ReceiveFrom(bArray, ref ep);
.....................
bArray =null;
}