public void NotifyClient(GameHubConnectionClient client, GameHubMessage message) { try { if (client.Connection.Connected) { GameHubConnectivity.SendMessageToClient(client, message); } } catch { return; } }
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); }
public static void SendMessageToClient(GameHubConnectionClient client, GameHubMessage message) { SendMessageToClient(client.Connection, message); }