public Socket GetClientWithRemoteEndPoint(IPEndPoint endPoint)
        {
            Socket result;

            this._clients.TryGetValue(AbstractTcpSocket.keyForEndPoint(endPoint), out result);
            return(result);
        }
        protected override void onReceived(IAsyncResult ar)
        {
            ReceiveVO receiveVO = (ReceiveVO)ar.AsyncState;
            int       num       = 0;

            try
            {
                num = receiveVO.socket.EndReceive(ar);
            }
            catch (SocketException)
            {
            }
            if (num == 0)
            {
                if (receiveVO.socket.Connected)
                {
                    this.removeClient(receiveVO.socket);
                    return;
                }
            }
            else
            {
                string text = AbstractTcpSocket.keyForEndPoint((IPEndPoint)receiveVO.socket.RemoteEndPoint);
                this._logger.Debug(string.Concat(new object[]
                {
                    "Server received ",
                    num,
                    " bytes from ",
                    text
                }));
                base.triggerOnReceived(receiveVO, num);
                base.receive(receiveVO);
            }
        }
        void onConnected(IAsyncResult ar)
        {
            Socket socket = (Socket)ar.AsyncState;
            bool   flag   = false;

            try
            {
                socket.EndConnect(ar);
                flag = true;
            }
            catch (SocketException ex)
            {
                this._logger.Error(ex.Message);
            }
            if (flag)
            {
                IPEndPoint endPoint = (IPEndPoint)socket.RemoteEndPoint;
                this._logger.Debug("Client connected to " + AbstractTcpSocket.keyForEndPoint(endPoint));
                base.receive(new ReceiveVO(socket, new byte[socket.ReceiveBufferSize]));
                if (this.OnConnected != null)
                {
                    this.OnConnected(this);
                }
            }
        }
        void addClient(Socket client)
        {
            string text = AbstractTcpSocket.keyForEndPoint((IPEndPoint)client.RemoteEndPoint);

            this._clients.Add(text, client);
            this._logger.Debug("Server accepted new client connection from " + text);
            base.receive(new ReceiveVO(client, new byte[client.ReceiveBufferSize]));
            if (this.OnClientConnected != null)
            {
                this.OnClientConnected(this, client);
            }
        }
예제 #5
0
        protected void send(Socket socket, byte[] buffer)
        {
            string text = AbstractTcpSocket.keyForEndPoint((IPEndPoint)socket.RemoteEndPoint);

            this._logger.Debug(string.Concat(new object[]
            {
                "Sending ",
                buffer.Length,
                " bytes via ",
                text
            }));
            socket.BeginSend(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(this.onSent), socket);
        }