示例#1
0
        private void ConnectionReceived(TcpClient tcpClient)
        {
            try
            {
                SocketStateObject headerState = new SocketStateObject(AosHeader.Length);
                Socket            client      = tcpClient.Client;
                headerState.socket = client;

                var sync = client.BeginReceive(headerState.buffer, 0, headerState.bufferSize, 0, new AsyncCallback(ReceiveHeaderCallback), headerState);
                //sync.AsyncWaitHandle.WaitOne();
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"Can't recieve data");
            }
        }
示例#2
0
        private void ReceiveBodyCallback(IAsyncResult ar)
        {
            try
            {
                SocketStateObject bodyState = (SocketStateObject)ar.AsyncState;
                Socket            client    = bodyState.socket;

                int     bytesRead = client.EndReceive(ar);
                AosBody aosBody   = AosBody.ToAosBody(bodyState.buffer);

                AosBodyReceivedEvent?.Invoke(this, new AosBodyEventArgs(aosBody));

                SocketStateObject headerState = new SocketStateObject(AosHeader.Length);
                headerState.socket = client;

                var sync = client.BeginReceive(headerState.buffer, 0, headerState.bufferSize, 0, new AsyncCallback(ReceiveHeaderCallback), headerState);
                //sync.AsyncWaitHandle.WaitOne();
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"Can't recieve data");
            }
        }