コード例 #1
0
        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;
        }
コード例 #2
0
ファイル: GameServer.cs プロジェクト: mikeries/Empire
        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);
        }
コード例 #3
0
ファイル: GameClient.cs プロジェクト: mikeries/Empire
        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;
            }
        }