Esempio n. 1
0
        private void DoReceiveInThread()
        {
            EndPoint remotePoint = IPUtils.GetIPEndPointAny(AddressFamily.InterNetwork, 0);
            int      cnt         = m_SystemSocket.ReceiveFrom(m_RecvBufferTemp, m_RecvBufferTemp.Length, SocketFlags.None, ref remotePoint);

            if (cnt > 0)
            {
                m_RecvBufferTempReader.Attach(m_RecvBufferTemp, cnt);
                byte[] m_32b = new byte[4];
                m_RecvBufferTempReader.ReadBytes(m_32b, 0, 4);
                uint sid = BitConverter.ToUInt32(m_32b, 0);
                //uint sid = m_RecvBufferTempReader.ReadUInt();


                lock (m_mapSession)
                {
                    ISession session = null;

                    if (sid == 0)
                    {
                        //来自Client的第1个包,只能是鉴权包
                        sid     = SessionID.NewID();
                        session = new KCPSession(sid, HandleSessionSend, m_listener);
                        m_mapSession.Add(session.id, session);
                    }
                    else
                    {
                        session = m_mapSession[sid];
                    }


                    if (session != null)
                    {
                        session.Active(remotePoint as IPEndPoint);
                        session.DoReceiveInGateway(m_RecvBufferTemp, cnt);
                    }
                    else
                    {
                        Debuger.LogWarning("无效的包! sid:{0}", sid);
                    }
                }
            }
        }
Esempio n. 2
0
        private void DoReceiveInThread()
        {
            EndPoint remotePoint = IPUtility.GetIPEndPointAny(AddressFamily.InterNetwork, 0);
            int      cnt         = currentSocket.ReceiveFrom(byteBuffer, byteBuffer.Length, SocketFlags.None, ref remotePoint);

            if (cnt > 0)
            {
                recvBufferTempReader.Attach(byteBuffer, cnt);
                byte[] convBytes = new byte[4];
                recvBufferTempReader.ReadBytes(convBytes, 0, 4);
                uint sessionid = BitConverter.ToUInt32(convBytes, 0);

                lock (sessions)
                {
                    ISession session = null;
                    if (sessionid == 0)
                    {
                        sessionid = SessionIDGenerator.GetNextSessionID();
                        session   = new KCPSession(sessionid, HandleSessionSend, sessionListener);
                        sessions.Add(session.id, session);
                    }
                    else
                    {
                        if (sessions.ContainsKey(sessionid))
                        {
                            session = sessions[sessionid];
                        }
                    }

                    if (session != null)
                    {
                        session.Active(remotePoint as IPEndPoint);
                        session.DoReceiveInGateway(byteBuffer, cnt);
                    }
                    else
                    {
                        Debuger.LogWarning("无效的包! sessionid:{0}", sessionid);
                    }
                }
            }
        }
Esempio n. 3
0
        private void DoReceiveInThread()
        {
            EndPoint remotePoint = IPUtility.GetIPEndPointAny(AddressFamily.InterNetwork, 0);
            int      cnt         = systemSocket.ReceiveFrom(recvBufferTemp, recvBufferTemp.Length, SocketFlags.None, ref remotePoint);

            if (cnt > 0)
            {
                recvBufferTempReader.Attach(recvBufferTemp, cnt);
                byte[] m_32b = new byte[4];
                recvBufferTempReader.ReadBytes(m_32b, 0, 4);
                uint sid = BitConverter.ToUInt32(m_32b, 0);

                lock (mapSession)
                {
                    FSPSession session = null;
                    if (sid == 0)
                    {
                        Debuger.LogError("基于KCP的Sid为0,该包需要被丢掉");
                    }
                    else
                    {
                        if (mapSession.ContainsKey(sid))
                        {
                            session = mapSession[sid];
                        }
                    }

                    if (session != null)
                    {
                        session.Active(remotePoint as IPEndPoint);
                        session.DoReceiveInGateway(recvBufferTemp, cnt);
                    }
                    else
                    {
                        Debuger.LogWarning("无效的包! sid:{0}", sid);
                    }
                }
            }
        }