private void InitStartIpv6() { if (Interlocked.CompareExchange(ref _isListened, 1, 0) != 0) { return; } listen?.Close(); listen = GetNewSocketInfo(); listen.Bind(new IPEndPoint(IPAddress.Any, this.listen_port)); listen.Listen(100); var e = SocketAsyncEventArgsPool.GetNewAsyncEventArgs(); accept_listen_async_arg = e; e.Completed += (S, EE) => { AcceptAsyncCallback(listen, EE); }; ProessAccept(listen, e); listenIPv6?.Close(); listenIPv6 = GetNewSocketIPv6Info(); listenIPv6.Bind(new IPEndPoint(IPAddress.IPv6Any, this.listen_port)); listenIPv6.Listen(100); var e_ipv6 = SocketAsyncEventArgsPool.GetNewAsyncEventArgs(); accept_listen_IPv6_async_arg = e_ipv6; e_ipv6.Completed += (S, EE) => { AcceptAsyncCallback(listenIPv6, EE); }; ProessAccept(listenIPv6, e_ipv6); }
private void Initializer() { client?.Close(); send_arg?.Dispose(); client = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); send_arg = SocketAsyncEventArgsPool.GetNewAsyncEventArgs(); send_arg.AcceptSocket = client; send_arg.SetBuffer(new byte[1024 * 2], 0, 1024 * 2); send_arg.Completed += Send_arg_Completed; }
private void Initializer() { server?.Close(); rec_arg?.Dispose(); _isReceived = 0; _isDisposed = 0; server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); rec_arg = SocketAsyncEventArgsPool.GetNewAsyncEventArgs(); rec_arg.AcceptSocket = server; rec_arg.SetBuffer(new byte[1024 * 4], 0, 1024 * 4); rec_arg.Completed += Rec_arg_Completed; server.Bind(new IPEndPoint(IPAddress.Parse(_ip), _port)); }
private void InitStartIpv6() { if (Interlocked.CompareExchange(ref _isListened, 1, 0) != 0) { return; } listen?.Close(); listen = GetNewSocketInfo(); if (Net.SocketHelper.PortInUse(this.listen_port)) { var pro = Net.SocketHelper.PortInUseProcess(this.listen_port); if (pro != null) { throw new System.Exception($@"服务端口【{ this.listen_port}】已经被其他进程占用。占用进程信息: PID:{pro.Id} ProcessName:{pro.ProcessName}"); } } listen.Bind(new IPEndPoint(IPAddress.Any, this.listen_port)); listen.Listen(100); var e = SocketAsyncEventArgsPool.GetNewAsyncEventArgs(); accept_listen_async_arg = e; e.Completed += (S, EE) => { AcceptAsyncCallback(listen, EE); }; ProessAccept(listen, e); listenIPv6?.Close(); listenIPv6 = GetNewSocketIPv6Info(); listenIPv6.Bind(new IPEndPoint(IPAddress.IPv6Any, this.listen_port)); listenIPv6.Listen(100); var e_ipv6 = SocketAsyncEventArgsPool.GetNewAsyncEventArgs(); accept_listen_IPv6_async_arg = e_ipv6; e_ipv6.Completed += (S, EE) => { AcceptAsyncCallback(listenIPv6, EE); }; ProessAccept(listenIPv6, e_ipv6); }