Esempio n. 1
0
        public void ReadMessage(string message, ulong clientId)
        {
            IMessage <IGMController> messageObject = null;

            if (message == "client disconnected")
            {
                GameController.CloseGame();
            }
            else
            {
                messageObject = ServerReader.GetObjectFromXML <IGMController>(message, clientId);//message must be without any \0 characters
                messageObject?.Process(GameController);
            }
            ConsoleWriter.Show("GM Client: " + clientId + " sent message of type: " + messageObject?.GetType().Name);
        }
        public void ReadMessage(string message, ulong clientId)
        {
            IMessage <IMainController> messageObject = null;

            if (message == "client disconnected")
            {
                mainManager.RemoveClient(clientId);
            }
            else
            {
                messageObject = ServerReader.GetObjectFromXML <IMainController>(message, clientId);//message must be without any \0 characters
                messageObject?.Process(mainManager);
            }
            ConsoleWriter.Show("Unknown Client: " + clientId + " sent message of type: " + messageObject?.GetType().Name);
        }
Esempio n. 3
0
        /// <summary>
        /// (Re-)Starts the server, waits for a client, initializes the components and waits for input from client.
        /// </summary>
        private static async Task StartServer()
        {
            MiBands.Clear();
            _server?.Stop();
            _listenForCommands = true;
            _server            = TcpListener.Create(Consts.ServerData.PORT);
            _server.Start();

            Console.WriteLine("Waiting for client...");
            _client = await _server.AcceptTcpClientAsync();

            Console.WriteLine("Client connected.");

            NetworkStream stream = _client.GetStream();

            _writer = new ServerWriter(stream);
            _reader = new ServerReader(stream);
            await ListenForCommands();
        }