public async Task Initialize() { if (_myAddress != null) { return; // already been initialized. } try { using (StreamSocket socket = await _connection.ConnectToTCP(_serverAddress, NetworkPorts.LobbyServerPort)) { _myAddress = socket.Information.LocalAddress.DisplayName; } await _connection.StartTCPListener(NetworkPorts.LobbyClientPort, ProcessRequest); } catch (Exception) { // Could not reach lobby. //TODO: Create custom exceptions to be thrown by lobby and caught and handled by the gameView. LobbyCommandPacket packet = new LobbyCommandPacket("Client", LobbyCommands.Disconnected); OnLobbyCommand(packet); } return; }
private async Task UpdateAllClients() { LobbyData data = new LobbyData(_playerList, _gameList); var destinations = from player in _playerList.Values select player.IPAddress; foreach (string address in destinations) { using (StreamSocket socket = await _connection.ConnectToTCP(address, NetworkPorts.LobbyClientPort)) { await _connection.SendTCPData(socket, data); } } }