Beispiel #1
0
        /// <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;
        }
Beispiel #2
0
        void Init(Socket socket, EndPoint remoteEndPoint, ThreadSyncActions tsa)
        {
            _socket        = socket;
            RemoteEndPoint = remoteEndPoint;
            _tsa           = tsa;

            _sendEA                = new SocketAsyncEventArgs();
            _sendEA.Completed     += OnAsyncEventCompleted;
            _sendEA.RemoteEndPoint = RemoteEndPoint;
        }
Beispiel #3
0
        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;
        }
Beispiel #4
0
 internal UdpSendChannel(Socket socket, EndPoint remoteEndPoint, ThreadSyncActions tsa)
 {
     Init(socket, remoteEndPoint, tsa);
 }
Beispiel #5
0
        internal UdpSendChannel(Socket socket, string remoteHost, int remotePort, ThreadSyncActions tsa)
        {
            var remoteEndPoint = new IPEndPoint(IPAddress.Parse(remoteHost), remotePort);

            Init(socket, remoteEndPoint, tsa);
        }