コード例 #1
0
ファイル: TCPClient.cs プロジェクト: isoundy000/L3D
        public void Send <T>(NetCmdBase ncb)
        {
            Debug.Log("TCP = " + typeof(T).ToString());
            SendCmdPack scp;

            scp.Cmd  = ncb;
            scp.Hash = Utility.GetHash(typeof(T).ToString());// TypeSize<T>.HASH;
            if (_mSendList.HasSpace())
            {
                _mSendList.AddItem(scp);
            }
            else
            {
                LogMgr.Log("发送命令队列已满");
            }

            byte[] sendData = NetCmdHelper.CmdToBytes(_mSendList.GetItem(), 0);
            if (sendData != null)
            {
                Send(sendData);
            }
            else
            {
                Debug.LogError("发送数据异常");
            }
        }
コード例 #2
0
 public void Update(float delta)
 {
     while (m_CompletionList.HasItem())
     {
         DownloadData dd = m_CompletionList.GetItem();
         if (dd.Type != DownloadType.DOWNLOAD_DEFAULT)
         {
             DownloadHandler.Handle(dd);
         }
     }
 }
コード例 #3
0
    public void _FtpThread()
    {
        while (true)
        {
            if (m_DownList.HasItem() == false)
            {
                Thread.Sleep(100);
                continue;
            }

            DownloadData dd = m_DownList.GetItem();
            if (USE_NEW_FTP == 0)
            {
                DownMultiFile_OldFTP(dd);
            }
            else
            {
                bool bRet = false;
                try
                {
                    uint recvTick = Utility.GetTickCount();
                    if (dd.Type == DownloadType.DOWNLOAD_MULTI_FILE)
                    {
                        bRet = DownMultiFiles(dd);
                    }
                    else
                    {
                        bRet = DownSingleFiles(dd);
                    }
                    recvTick = Utility.GetTickCount() - recvTick;
                }
                catch (System.Exception e)
                {
                    ReportException.Instance.AddException("FTPDown Err:" + e.ToString());
                }
                dd.DownState = bRet ? DownloadState.DS_DOWNLOADED_OK : DownloadState.DS_DOWNLOADED_ERROR;
                if (dd.Type != DownloadType.DOWNLOAD_DEFAULT)
                {
                    m_CompletionList.AddItem(dd);
                }
            }

            Thread.Sleep(100);
        }
    }
コード例 #4
0
        public bool Update(float delta)
        {
            if (tCPClient != null)
            {
                tCPClient.Update();
            }

            if (CanProcessCmd)
            {
                while (cmdList.HasItem())
                {
                    NetCmdPack nc  = cmdList.GetItem();
                    IEvent     evt = new Event(nc.cmd.GetCmdTypeToString());
                    evt.parameter = nc;
                    DispatchEvent(evt);
                }
            }

            return(true);
        }
コード例 #5
0
    public bool Update(float delta)
    {
        if (m_TCPClient != null)
        {
            m_TCPClient.Update();
        }

        if (m_Handler != null && m_Handler.CanProcessCmd())
        {
            while (m_CmdList.HasItem() && m_Handler != null)
            {
                NetCmdPack nc = m_CmdList.GetItem();
                if (m_Handler.Handle(nc) == false)
                {
                    if (HeaderManager.Instance.HandleCmd(nc) == false)
                    {
                        m_FinalHandler.Handle(nc);
                    }
                }
            }
        }
        return(true);
    }
コード例 #6
0
ファイル: UDPClient.cs プロジェクト: profiles/Fish
    public void ThreadRecv()
    {
        Socket     socket      = m_Socket;
        int        recvSize    = 0;
        const uint halfTimeout = 1000;

        while (m_bConnected)
        {
            uint tick = GetTickCount();
#if UNITY_EDITOR
            if (SceneMain.Exited)
            {
                CloseSocket();
                break;
            }
#endif
            for (int i = 0; i < 2; ++i)
            {
                try
                {
                    recvSize = socket.Receive(BUFF, 0, BUFF.Length, SocketFlags.None);
                    if (recvSize > 0)
                    {
                        if (RecvData(socket, recvSize) == false)
                        {
                            CloseSocket();
                            m_bNotify = true;
                            return;
                        }
                        else
                        {
                            m_RecvTick = tick;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                catch
                {
                    break;
                }
            }
            if (tick - m_RecvTick > ClientSetting.TIMEOUT)
            {
                CloseSocket();
                m_bNotify = true;
                return;
            }
            if (m_SendBuff != null)
            {
                if (tick - m_SendCmdTick > ClientSetting.UDP_RESEND_TICK || m_bSendBackID)
                {
                    ToBytes(SET_ANSWER(m_RecvID), m_SendBuff, 0);
                    if (Send(socket, m_SendBuff))
                    {
                        m_bSendBackID = false;
                        m_SendTick    = m_SendCmdTick = tick;
                    }
                }
            }
            else if (m_SendList.HasItem())
            {
                m_SendBuff = NetCmdHelper.CmdToBytes(m_SendList.GetItem(), 8);
                ++m_SendID;
                ToBytes(SET_ANSWER(m_RecvID), m_SendBuff, 0);
                ToBytes(m_SendID, m_SendBuff, 4);
                if (Send(socket, m_SendBuff))
                {
                    m_bSendBackID = false;
                    m_SendTick    = m_SendCmdTick = tick;
                }
                else
                {
                    m_SendCmdTick = 0;
                }
            }
            else if (m_bSendBackID)
            {
                ToBytes(SET_ANSWER(m_RecvID), HEARBEAT_CMD, 0);
                if (Send(socket, HEARBEAT_CMD))
                {
                    m_SendTick    = tick;
                    m_bSendBackID = false;
                }
            }
            else if (tick - m_SendTick > halfTimeout)
            {
                if (Send(socket, HEARBEAT_CMD))
                {
                    m_SendTick = tick;
                }
            }
            Thread.Sleep(1);
        }
    }
コード例 #7
0
ファイル: TCPClient.cs プロジェクト: profiles/Fish
    public void ThreadRecv()
    {
        Socket socket = m_Socket;
        int    ret    = 0;

        byte[]     sendData = null;
        const uint timeout  = 1000;

        byte[] HEARBEAT_CMD = new byte[4] {
            0xff, 0xff, 0xff, 0xff
        };
        while (m_bConnected)
        {
            try
            {
                int idx = m_Offset + m_RecvSize;
                ret = socket.Receive(m_Buff, idx, m_Buff.Length - idx, SocketFlags.None);
            }
            catch
            {
                ret = 0;
                if (socket.Connected == false)
                {
                    CloseSocket();
                    m_bNotify = true;
                    break;
                }
            }
            uint tick = GetTickCount();
            if (ret > 0)
            {
                m_RecvSize += ret;
                if (!RecvData(m_Buff))
                {
                    break;
                }
                m_RecvTick = tick;
            }
            else if (tick - m_RecvTick > ClientSetting.TIMEOUT)
            {
                m_bNotify = true;
                CloseSocket();
                break;
            }
            if (sendData != null)
            {
                if (Send(socket, sendData))
                {
                    sendData   = null;
                    m_SendTick = tick;
                }
            }
            if (m_SendList.HasItem())
            {
                sendData = NetCmdHelper.CmdToBytes(m_SendList.GetItem(), 0);
                if (Send(socket, sendData))
                {
                    sendData   = null;
                    m_SendTick = tick;
                }
            }
            else if (tick - m_SendTick > timeout)
            {
                if (Send(socket, HEARBEAT_CMD))
                {
                    m_SendTick = tick;
                }
            }
            Thread.Sleep(ClientSetting.SLEEP_TIME);
        }
    }
コード例 #8
0
        public void ThreadRecv()
        {
            Socket     socket      = _mSocket;
            int        recvSize    = 0;
            const uint halfTimeout = 1000;

            while (_mBConnected)
            {
                uint tick = GetTickCount();
#if UNITY_EDITOR
//                if (SceneMain.Exited)
//                {
//                    CloseSocket();
//                    break;
//                }
#endif
                for (int i = 0; i < 2; ++i)
                {
                    try
                    {
                        recvSize = socket.Receive(_buff, 0, _buff.Length, SocketFlags.None);
                        if (recvSize > 0)
                        {
                            if (RecvData(socket, recvSize) == false)
                            {
                                CloseSocket();
                                _mBNotify = true;
                                return;
                            }
                            else
                            {
                                _mRecvTick = tick;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                    catch
                    {
                        break;
                    }
                }
                if (tick - _mRecvTick > ClientSetting.TIMEOUT)
                {
                    CloseSocket();
                    _mBNotify = true;
                    return;
                }
                if (_mSendBuff != null)
                {
                    if (tick - _mSendCmdTick > ClientSetting.UDP_RESEND_TICK || _mBSendBackId)
                    {
                        ToBytes(SET_ANSWER(_mRecvId), _mSendBuff, 0);
                        if (Send(socket, _mSendBuff))
                        {
                            _mBSendBackId = false;
                            _mSendTick    = _mSendCmdTick = tick;
                        }
                    }
                }
                else if (_mSendList.HasItem())
                {
                    _mSendBuff = NetCmdHelper.CmdToBytes(_mSendList.GetItem(), 8);
                    ++_mSendId;
                    ToBytes(SET_ANSWER(_mRecvId), _mSendBuff, 0);
                    ToBytes(_mSendId, _mSendBuff, 4);
                    if (Send(socket, _mSendBuff))
                    {
                        _mBSendBackId = false;
                        _mSendTick    = _mSendCmdTick = tick;
                    }
                    else
                    {
                        _mSendCmdTick = 0;
                    }
                }
                else if (_mBSendBackId)
                {
                    ToBytes(SET_ANSWER(_mRecvId), _hearbeatCmd, 0);
                    if (Send(socket, _hearbeatCmd))
                    {
                        _mSendTick    = tick;
                        _mBSendBackId = false;
                    }
                }
                else if (tick - _mSendTick > halfTimeout)
                {
                    if (Send(socket, _hearbeatCmd))
                    {
                        _mSendTick = tick;
                    }
                }
                Thread.Sleep(1);
            }
        }