예제 #1
0
        public void Subscribe()
        {
            _subscribeSoure = new CancellationTokenSource();

            var token = _subscribeSoure.Token;

            GameHubConnectivity.Subscribe(Connection, MessageQueue, TimeSpan.FromMilliseconds(100), token);
        }
예제 #2
0
        private void HandleClientConnect(CancellationToken token)
        {
            Task.Factory.StartNew(async() =>
            {
                try
                {
                    if (Server.Pending())
                    {
                        var client        = await Server.AcceptTcpClientAsync();
                        var gameHubClient = new GameHubConnectionClient
                        {
                            Connection = client
                        };

                        lock (_clientsLock)
                        {
                            _clients.Add(gameHubClient);
                        }

                        GameHubConnectivity.Subscribe(client, MessageQueue, TimeSpan.FromMilliseconds(200), token);

                        var message = new GameHubMessage
                        {
                            SenderGamePort = ((IPEndPoint)Server.LocalEndpoint).Port,
                            Text           = "Welcome to the GameHub Server. I hope you enjoy yourself",
                            Status         = EMessageType.InitialServerConnection
                        };

                        NotifyClient(gameHubClient, message);
                    }
                }
                catch
                {
                    return;
                }
            }, token);
        }