private void Receive(byte[] message)
 {
     if (OnReceiveCallback != null)
     {
         OnReceiveCallback.Invoke(message);
     }
 }
示例#2
0
        private void OnReceive(IAsyncResult result)
        {
            var socket = result.AsyncState as Socket;

            if (!socket.Connected || !IsUse)
            {
                return;
            }
            try
            {
                var count = socket.EndReceive(result);
                if (count <= 0)
                {
                    // SocketLog("Close");
                    // Close();
                    // return;
                }
                else
                {
                    OnReceiveCallback?.Invoke(this, m_Buffer, count);
                }
                m_Socket.BeginReceive(m_Buffer, BufferCount, BufferRemain, SocketFlags.None, OnReceive, m_Socket);
            }
            catch (Exception e)
            {
                SocketLogError(e);
                Close();
            }
        }
示例#3
0
        protected virtual void HandleReceiveData(Request request, byte[] buffer, int length)
        {
            int headerLength = CLIENT_ID_LENGTH + CLIENT_ID_LENGTH;

            if (length < headerLength)
            {
                return;
            }

            var targetClientId = Encoding.UTF8.GetString(buffer, CLIENT_ID_LENGTH, CLIENT_ID_LENGTH);

            if (targetClientId != ClientId)
            {
                return;
            }

            var data = buffer.SubArray(headerLength, length - headerLength);

            using (new MethodUtils.Unlocker(this)) {
                OnReceiveCallback?.Invoke(new Request()
                {
                    clientId = Encoding.UTF8.GetString(buffer, 0, CLIENT_ID_LENGTH)
                }, data, length - headerLength);
            }
        }
示例#4
0
        protected override void HandleReceiveData(Request request, byte[] buffer, int length)
        {
            if (length < SESSION_ID_LENGTH)
            {
                return;
            }

            request.sessionId = Encoding.UTF8.GetString(buffer, 0, SESSION_ID_LENGTH);
            var data = buffer.SubArray(SESSION_ID_LENGTH, length - SESSION_ID_LENGTH);

            lastActiveTime = DateTime.Now;
            using (new MethodUtils.Unlocker(this)) {
                OnReceiveCallback?.Invoke(request, data, data.Length);
            }
        }