/// <summary> /// 销毁监听 /// </summary> public void Dispose() { if (null != _receiveEA) { _receiveEA.Completed -= OnAsyncEventCompleted; _receiveEA = null; } if (_socket != null) { _socket.Close(); _socket.Dispose(); try { _socket.Shutdown(SocketShutdown.Both); } catch { } _socket = null; } onReceiveData = null; _receiveBuffer = null; _tsa = null; }
void Init(Socket socket, EndPoint remoteEndPoint, ThreadSyncActions tsa) { _socket = socket; RemoteEndPoint = remoteEndPoint; _tsa = tsa; _sendEA = new SocketAsyncEventArgs(); _sendEA.Completed += OnAsyncEventCompleted; _sendEA.RemoteEndPoint = RemoteEndPoint; }
public Socket Bind(int port, ushort bufferSize, ThreadSyncActions tsa) { Port = port; _receiveBuffer = new byte[bufferSize]; _tsa = tsa; _localEndPoint = new IPEndPoint(IPAddress.Any, port); _receiveEA = new SocketAsyncEventArgs(); _receiveEA.Completed += OnAsyncEventCompleted; _receiveEA.RemoteEndPoint = _localEndPoint; _socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); _socket.Bind(_localEndPoint); StartReceive(); return _socket; }
internal UdpSendChannel(Socket socket, EndPoint remoteEndPoint, ThreadSyncActions tsa) { Init(socket, remoteEndPoint, tsa); }
internal UdpSendChannel(Socket socket, string remoteHost, int remotePort, ThreadSyncActions tsa) { var remoteEndPoint = new IPEndPoint(IPAddress.Parse(remoteHost), remotePort); Init(socket, remoteEndPoint, tsa); }