Exemple #1
0
        public void UpdateBytesSentLastFrame()
        {
            if (mBytesSentThisFrame > 0)
            {
                mBytesSentPerSecond.UpdatePerSecond((float)(mBytesSentThisFrame));

                mBytesSentThisFrame = 0;
            }
        }
Exemple #2
0
        public void ProcessQueuedPackets()
        {
            int totalReadByteCount = 0;

            NetIncomingMessage im;

            while ((im = mNetPeer.ReadMessage()) != null)
            {
                // handle incoming message
                switch (im.MessageType)
                {
                case NetIncomingMessageType.DebugMessage:
                case NetIncomingMessageType.ErrorMessage:
                case NetIncomingMessageType.WarningMessage:
                case NetIncomingMessageType.VerboseDebugMessage:
                    string text = im.ReadString();
                    LogHelper.LogInfo(text);
                    break;

                case NetIncomingMessageType.StatusChanged:
                    NetConnectionStatus status = (NetConnectionStatus)im.ReadByte();

                    string reason = im.ReadString();
                    LogHelper.LogInfo("status " + NetUtility.ToHexString(im.SenderConnection.RemoteUniqueIdentifier) + " " + status + ": " + reason);

                    if (status == NetConnectionStatus.Connected)
                    {
                        //LogHelper.LogInfo("Remote hail: " + im.SenderConnection.RemoteHailMessage.ReadString());
                    }
                    else if (status == NetConnectionStatus.Disconnected)
                    {
                        OnDisconnected();
                    }

                    //UpdateConnectionsList();
                    break;

                case NetIncomingMessageType.Data:
                    totalReadByteCount += im.LengthBytes;

                    ProcessPacket(im, im.SenderEndPoint);

                    break;

                case NetIncomingMessageType.UnconnectedData:
                    string msg = im.ReadString();
                    LogHelper.LogInfo(msg);
                    ProcessInternalMessage(msg);
                    break;

                default:
                    LogHelper.LogInfo("Unhandled type: " + im.MessageType + " " + im.LengthBytes + " bytes " + im.DeliveryMethod + "|" + im.SequenceChannel);
                    break;
                }
                mNetPeer.Recycle(im);
            }

            if (totalReadByteCount > 0)
            {
                mBytesReceivedPerSecond.UpdatePerSecond((float)(totalReadByteCount));
            }
        }
        public void ProcessQueuedPackets()
        {
            if (mNetPeer == null)
            {
                return;
            }

            int totalReadByteCount = 0;

            NetIncomingMessage im;
            bool isRecycle = true;

            //LogHelper.LogInfo($"ProcessQueuedPackets local:{mNetPeer.Port}");

            while ((im = mNetPeer.ReadMessage()) != null)
            {
                isRecycle = true;
                // handle incoming message
                switch (im.MessageType)
                {
                case NetIncomingMessageType.DebugMessage:
                case NetIncomingMessageType.ErrorMessage:
                case NetIncomingMessageType.WarningMessage:
                case NetIncomingMessageType.VerboseDebugMessage:
                    string text = im.ReadString();
                    LogHelper.LogInfo(text);
                    break;

                case NetIncomingMessageType.StatusChanged:
                {
                    NetConnectionStatus status = (NetConnectionStatus)im.ReadByte();

                    string reason = im.ReadString();
                    LogHelper.LogInfo($"UDP status {im.SenderConnection.m_remoteEndPoint} {status} {reason}");

                    if (status == NetConnectionStatus.Connected)
                    {
                        OnConnected();
                        //LogHelper.LogInfo("Remote hail: " + im.SenderConnection.RemoteHailMessage.ReadString());
                    }
                    else if (status == NetConnectionStatus.Disconnected)
                    {
                        OnDisconnected(im);
                    }

                    //UpdateConnectionsList();
                }
                break;

                case NetIncomingMessageType.TcpStatusChanged:
                {
                    NetConnectionStatus status = (NetConnectionStatus)im.ReadByte();

                    string reason = im.ReadString();
                    LogHelper.LogInfo("TCP status " + im.SenderEndPoint + " " + status + ": " + reason);

                    if (status == NetConnectionStatus.Connected)
                    {
                        //LogHelper.LogInfo("Remote hail: " + im.SenderConnection.RemoteHailMessage.ReadString());
                        OnConnected();
                    }
                    else if (status == NetConnectionStatus.Disconnected)
                    {
                        OnDisconnected(im);
                    }

                    //UpdateConnectionsList();
                }
                break;

                case NetIncomingMessageType.Data:
                    //LogHelper.LogInfo($"Recv from : {im.SenderEndPoint}, bytes: {im.LengthBytes}, local:{mNetPeer.Port}, sessionID:{im.GetSessionId()}, protocol:{GetProtocol(im)}" );

                    totalReadByteCount += im.LengthBytes;

                    //if(im.isTcp)
                    isRecycle = ReadPacket(im, im.SenderEndPoint);

                    break;

                case NetIncomingMessageType.UnconnectedData:
                    string msg = im.ReadString();
                    LogHelper.LogInfo(msg);
                    ProcessInternalMessage(msg);
                    break;

                default:
                    LogHelper.LogInfo("Unhandled type: " + im.MessageType + " " + im.LengthBytes + " bytes " + im.DeliveryMethod + "|" + im.SequenceChannel);
                    break;
                }

                if (isRecycle)
                {
                    mNetPeer.Recycle(im);
                }
            }

            if (totalReadByteCount > 0)
            {
                mBytesReceivedPerSecond.UpdatePerSecond((float)(totalReadByteCount));
            }
        }