Пример #1
0
        private void ReceiveThread()
        {
            while (IsActive)
            {
                try
                {
                    IPEndPoint ip   = new IPEndPoint(IPAddress.Any, 0);
                    byte[]     data = Receive(ref ip);

                    Session c = TcpService.Instance.GetSession(ip);

                    if (c == null)
                    {
                        Debug.Warning("KCPServer收到未知客户端的KCP消息!!!");
                    }
                    else
                    {
                        c.OnReceiveMessageKCP(data, ip);
                    }

                    Thread.Sleep(1);
                }
                catch (SocketException e)
                {
                    Debug.Log("KCP接收消息:" + e.Message);
                    continue;
                }
                catch (Exception e)
                {
                    Debug.Error("KCP接收消息:" + e.Message);
                    throw e;
                }
            }
        }