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; }
internal async Task StartServer() { EmpireSerializer serializer = new Network.EmpireSerializer(); _networkConnection = new PacketConnection(serializer); await _networkConnection.StartTCPListener(_gameData.HostPort, HandleRequest); await _networkConnection.StartUDPListener(_gameData.HostPort, HandleUpdate); _timer = new Timer(SyncTimer, _autoEvent, 200, 200); }
internal async Task CreateNetworkConnection() { if (_networkConnection == null) { EmpireSerializer serializer = new EmpireSerializer(); _networkConnection = new PacketConnection(serializer); await _networkConnection.StartTCPListener(_myPort, HandleRequest); await _networkConnection.StartUDPListener(_myPort, HandleUpdate); _serverSocket = await _networkConnection.ConnectToTCP(_gameData.HostIPAddress, _gameData.HostPort); _myAddress = _serverSocket.Information.LocalAddress.DisplayName; } }