예제 #1
0
        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.disconnectedByRemote(receiveVO.socket);
                    return;
                }
            }
            else
            {
                string text = AbstractTcpSocket.keyForEndPoint((IPEndPoint)receiveVO.socket.RemoteEndPoint);
                this._logger.Debug(string.Concat(new object[]
                {
                    "Client received ",
                    num,
                    " bytes from ",
                    text
                }));
                base.triggerOnReceived(receiveVO, num);
                base.receive(receiveVO);
            }
        }
예제 #2
0
        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);
                }
            }
        }
예제 #3
0
 protected void triggerOnReceived(ReceiveVO receiveVO, int bytesReceived)
 {
     if (this.OnReceived != null)
     {
         this.OnReceived(this, receiveVO.socket, AbstractTcpSocket.trimmedBytes(receiveVO.bytes, bytesReceived));
     }
 }
예제 #4
0
        public Socket GetClientWithRemoteEndPoint(IPEndPoint endPoint)
        {
            Socket result;

            this._clients.TryGetValue(AbstractTcpSocket.keyForEndPoint(endPoint), out result);
            return(result);
        }
예제 #5
0
        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);
            }
        }
예제 #6
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);
        }