コード例 #1
0
        public async Task SendAsync(CSharpMessage message)
        {
            if (IsConnected)
            {
                message.From = _uniqueKey;

                await _hubConnection.SendAsync("SendAsync", message);
            }
            else
            {
                if (OnLostConnection == null)
                {
                    throw new CSharpException("Lost connection to server.");
                }
                else
                {
                    OnLostConnection.Invoke(this, message);
                }
            }
        }
コード例 #2
0
        public override void Update(GameTime gameTime)
        {
            WasConnected = IsConnected;

            if (Started)
            {
                if (IsServer)
                {
                    NetIncomingMessage _msg;
                    while ((_msg = _Server.ReadMessage()) != null)
                    {
                        switch (_msg.MessageType)
                        {
                        case NetIncomingMessageType.Data:
                            var _incMsg = ReadMessage(_msg);
                            OnGotMessage?.Invoke(_incMsg);
                            break;

                        case NetIncomingMessageType.VerboseDebugMessage:
                        case NetIncomingMessageType.DebugMessage:
                        case NetIncomingMessageType.WarningMessage:
                        case NetIncomingMessageType.ErrorMessage:
                            Console.WriteLine(_msg.ReadString());
                            break;

                        default:
                            Console.WriteLine("Unhandled type: " + _msg.MessageType);
                            break;
                        }
                        _Server.Recycle(_msg);
                    }
                }
                else
                {
                    NetIncomingMessage _msg;
                    while ((_msg = _Client.ReadMessage()) != null)
                    {
                        switch (_msg.MessageType)
                        {
                        case NetIncomingMessageType.Data:
                            var _incMsg = ReadMessage(_msg);
                            OnGotMessage?.Invoke(_incMsg);
                            break;

                        case NetIncomingMessageType.VerboseDebugMessage:
                        case NetIncomingMessageType.DebugMessage:
                        case NetIncomingMessageType.WarningMessage:
                        case NetIncomingMessageType.ErrorMessage:
                            Console.WriteLine(_msg.ReadString());
                            break;

                        default:
                            Console.WriteLine("Unhandled type: " + _msg.MessageType);
                            break;
                        }
                        _Client.Recycle(_msg);
                    }
                }
            }

            if (IsConnected && !WasConnected)
            {
                OnNewConnection?.Invoke();
            }

            if (!IsConnected && WasConnected)
            {
                OnLostConnection?.Invoke();
            }
        }
コード例 #3
0
 /// <summary>
 ///     Raise the lost connection event
 /// </summary>
 protected void LostConnection()
 {
     OnLostConnection?.Invoke(this, EventArgs.Empty);
 }