Ejemplo n.º 1
0
        public void Tick_ReceivingData()
        {
            try
            {
                while (_tcpClient.Available > 0)
                {
                    byte[] cmdLenBuf  = new byte[VarTracerConst.ByteSize_Int];
                    int    cmdLenRead = _tcpClient.GetStream().Read(cmdLenBuf, 0, cmdLenBuf.Length);
                    int    cmdLen     = BitConverter.ToInt32(cmdLenBuf, 0);
                    if (cmdLenRead > 0 && cmdLen > 0)
                    {
                        byte[] buffer = new byte[cmdLen];
                        if (!NetUtil.ReadStreamData(_tcpClient, ref buffer))
                        {
                            throw new Exception("Read Stream Data Error!");
                        }

                        UsCmd           cmd    = new UsCmd(buffer);
                        UsCmdExecResult result = _cmdParser.Execute(cmd);
                        switch (result)
                        {
                        case UsCmdExecResult.Succ:
                            break;

                        case UsCmdExecResult.Failed:
                            NetUtil.Log("net cmd execution failed: {0}.", new UsCmd(buffer).ReadNetCmd());
                            break;

                        case UsCmdExecResult.HandlerNotFound:
                            NetUtil.Log("net unknown cmd: {0}.", new UsCmd(buffer).ReadNetCmd());
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                DisconnectOnError("error detected while receiving data.", ex);
            }
        }
Ejemplo n.º 2
0
    public void Tick_ReceivingData()
    {
        try
        {
            while (_tcpClient.Available > 0)
            {
                byte[] cmdLenBuf  = new byte[2];
                int    cmdLenRead = _tcpClient.GetStream().Read(cmdLenBuf, 0, cmdLenBuf.Length);
                ushort cmdLen     = BitConverter.ToUInt16(cmdLenBuf, 0);
                if (cmdLenRead > 0 && cmdLen > 0)
                {
                    byte[] buffer = new byte[cmdLen];
                    int    len    = _tcpClient.GetStream().Read(buffer, 0, buffer.Length);

                    UsCmd           cmd    = new UsCmd(buffer);
                    UsCmdExecResult result = _cmdParser.Execute(cmd);
                    switch (result)
                    {
                    case UsCmdExecResult.Succ:
                        break;

                    case UsCmdExecResult.Failed:
                        NetUtil.Log("net cmd execution failed: {0}.", new UsCmd(buffer).ReadNetCmd());
                        break;

                    case UsCmdExecResult.HandlerNotFound:
                        NetUtil.Log("net unknown cmd: {0}.", new UsCmd(buffer).ReadNetCmd());
                        break;
                    }

                    len++; // warning CS0219: The variable `len' is assigned but its value is never used
                }
            }
        }
        catch (Exception ex)
        {
            DisconnectOnError("error detected while receiving data.", ex);
        }
    }