public UdpSocket(int port, IPEndPoint remote, bool subThread = true, PackType type = PackType.Total, int es = 262144) { endPoint = remote; //Links = new Linker[thread * 1024]; IPEndPoint ip = new IPEndPoint(IPAddress.Any, port); soc = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); //new UdpClient(_port);//new IPEndPoint(IPAddress.Parse(ip), soc.Bind(ip); soc.ReceiveTimeout = 1000; if (type != PackType.None) { Packaging = true; envelope = new TcpEnvelope(es); envelope.type = type; } running = true; auto = subThread; if (thread == null) { thread = new ThreadEx(Run); thread.Start(); } queue = new QueueBuffer <SocData>(); }
public void ConnectServer(IPEndPoint remote, IPEndPoint bind = null) { if (thread != null) { return; } localBind = bind; close = false; iep = remote; if (thread == null) { thread = new ThreadEx(Run); thread.Start(); } }
public void Start() { if (_port == 0) { _port = FreePort.FindNextAvailableUDPPort(10000); } IPEndPoint ip = new IPEndPoint(IPAddress.Any, _port); soc = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); //new UdpClient(_port);//new IPEndPoint(IPAddress.Parse(ip), soc.Bind(ip); soc.ReceiveTimeout = 1000; running = true; if (thread == null) { //创建消息接收线程 thread = new ThreadEx(Run); thread.Start(); } }
/// <summary> /// UdpServer构造 /// </summary> /// <param name="port"></param> /// <param name="remote"></param> /// <param name="subThread"></param> public UdpServer(int port, int remote, bool subThread = true, PackType type = PackType.Total) { queue = new Queue <SocData>(); packType = type; remotePort = remote; //udp服务器端口绑定 IPEndPoint ip = new IPEndPoint(IPAddress.Any, port); soc = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); //new UdpClient(_port);//new IPEndPoint(IPAddress.Parse(ip), soc.Bind(ip); running = true; auto = subThread; links = new List <UdpLink>(); if (thread == null) { //创建消息接收线程 thread = new ThreadEx(Run); thread.Start(); } }
public void Start() { if (server == null) { server = new ThreadEx(AcceptClient); server.Start(); } if (threadTimer == null) { threadTimer = new ThreadTimer(); threadTimer.Interal = 1000; threadTimer.Tick = (o, e) => { try { Heartbeat(); } catch (Exception ex) { UnityEngine.Debug.Log(ex.StackTrace); } }; } }
public LinkThread(int size = 2048) : base(size) { running = true; thread = new ThreadEx(Run); thread.Start(); }