码迷,mamicode.com
首页 > 其他好文 > 详细

UDP通信

时间:2017-09-25 14:43:12      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:data   .so   point   while   .text   text   etop   ogr   int   

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Net.Sockets;
using System.Threading;

namespace ConsoleApp4
{
class Program
{
static void Main(string[] args)
{
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
IPEndPoint iep1 = new IPEndPoint(IPAddress.Broadcast, 8093);
IPEndPoint iep2 = new IPEndPoint(IPAddress.Parse("192.168.31.255"), 9001);
string hostname = Dns.GetHostName();
byte[] data = Encoding.ASCII.GetBytes(hostname);

sock.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.Broadcast, 1);
Thread thread1 = new Thread(send);
Thread thread2 = new Thread(send);
Thread thread3 = new Thread(send);
Thread thread4 = new Thread(send);
Thread thread5 = new Thread(send);
Thread thread6 = new Thread(send);
thread1.Start();
thread2.Start();
thread3.Start();
thread4.Start();
thread5.Start();
thread6.Start();

void send() {
while (true)
{
sock.SendTo(data, iep1);
sock.SendTo(data, iep2);
}

}


}
}
}

UDP通信

标签:data   .so   point   while   .text   text   etop   ogr   int   

原文地址:http://www.cnblogs.com/zhuzhengchao2017/p/7591458.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!