Example #1
0
 public void Login(string username, string password)
 {
     Console.WriteLine("login packet, username: "******", wachtwoord: " + password);
     //Test sending back:
     NetworkCommunication.SendPacket(new PacketLogin(true), stream);
     //Moet je maar ff in project pakke en kopiere en aanpasse op structuur;
 }
Example #2
0
 public void stopTraject()
 {
     bicycle.sendData(ConnectionToBicycle.RESET);
     traject.Abort();
     //save logfile to server
     NetworkCommunication.SendPatient(tcpClient, patient);
 }
Example #3
0
 private void receiveUpdate()
 {
     while (true)
     {
         string data = NetworkCommunication.ReadMessage(tcpClient);
         doctor.patients = JsonConvert.DeserializeObject <List <Patient> >(data);
     }
 }
Example #4
0
 private void Awake()
 {
     instance       = this;
     playerScore    = 0;
     plateformLayer = 0;
     ballLayer      = 0;
     healthValue    = 2;
     networkServer  = new NetworkCommunication("127.0.0.1", 8829);
     interfaceManager.InitUI();
 }
 /// <summary>
 /// Receive thread.</summary>
 private void ReceiveThread()
 {
     while (true)
     {
         Packet packet = NetworkCommunication.ReadPacket(ssl);
         if (packet != null)
         {
             packet.handleClientSide(parent);
         }
     }
 }
Example #6
0
        private void DoConnection(Uri serverUri, Action <string> reporter)
        {
            while (IsTerminated == false)
            {
                try
                {
                    TcpClient client = new TcpClient();
                    client.Connect(serverUri.Host, serverUri.Port);
                    NetworkStream stream = client.GetStream();

                    reporter("Connected");

                    StreamReader reader = new StreamReader(stream, Encoding.UTF8);
                    StreamWriter writer = new StreamWriter(stream, Encoding.UTF8);

                    while (client.Connected && IsTerminated == false)
                    {
                        string line = reader.ReadLine();
                        NetworkCommunication message = JsonHelper.DeserialiazeWithType <NetworkCommunication>(line);
                        reporter("Received message: " + message.GetType());
                        var answer = ProcessMessage(message);
                        if (answer != null)
                        {
                            var str = JsonHelper.SerialiazeWithType(answer);
                            writer.WriteLine(str);
                            writer.Flush();
                        }
                    }

                    // Close everything.
                    reader.Close();
                    writer.Close();
                    stream.Close();
                    client.Close();
                }
                catch (Exception exp)
                {
                    reporter("Error: " + exp.Message);
                }
                for (int i = 1; i <= 50; i++)
                {
                    if (IsTerminated)
                    {
                        break;
                    }
                    Thread.Sleep(TimeSpan.FromSeconds(0.1));
                }
            }
        }
Example #7
0
        private ICommunication CreateConnection()
        {
            ICommunication returnType = null;

            switch (ConnControl.GetConnectionType())
            {
            case ConnectionType.Bluetooth:
                returnType = new BluetoothCommunication();
                break;

            case ConnectionType.WiFi:
                returnType = new NetworkCommunication(ConnControl.GetIpAddress());
                break;
            }

            return(returnType);
        }
Example #8
0
        public NetworkMessage Query(NetworkCommunication request)
        {
            var    message = JsonHelper.SerialiazeWithType(request);
            string answerMessage;

            lock (ioLock)
            {
                writer.WriteLine(message);
                if (request is NetworkMessage)
                {
                    return(null);
                }

                answerMessage = reader.ReadLine();
            }
            NetworkMessage answer = JsonHelper.DeserialiazeWithType <NetworkMessage>(answerMessage);

            return(answer);
        }
Example #9
0
 NetworkMessage ProcessMessage(NetworkCommunication communication)
 {
     if (communication is CheckRequest)
     {
         return(ProcessCheck(communication as CheckRequest));
     }
     else if (communication is NewGameMessage)
     {
         ProcessNewGame(communication as NewGameMessage);
     }
     else if (communication is DecisionRequest)
     {
         return(ProcessDecision(communication as DecisionRequest));
     }
     else if (communication is WelcomeRequest)
     {
         return(ProcessWelcome(communication as WelcomeRequest));
     }
     return(null);
 }
Example #10
0
        private ICommunication CreateConnection()
        {
            ICommunication returnType = null;

            switch (ConnControl.GetConnectionType())
            {
            case ConnectionType.Bluetooth:
                //returnType = new BluetoothCommunication(ConnControl.GetComportNumber());
                //break;
                throw new NotSupportedException("Bluetooth is not supported at the moment");

            case ConnectionType.Usb:
                returnType = new UsbCommunication();
                break;

            case ConnectionType.WiFi:
                returnType = new NetworkCommunication(ConnControl.GetIpAddress());
                break;
            }

            return(returnType);
        }
Example #11
0
        private void Handler(object obj)
        {
            TcpClient client = obj as TcpClient;

            while (true)
            {
                string   data  = NetworkCommunication.ReadMessage(client);
                string[] param = data.Split('|');
                Console.WriteLine($"received: {data}");
                switch (param[0])
                {
                case "1":
                    Patient patient = JsonConvert.DeserializeObject <Patient>(param[1]);
                    AddPatientSession(patient);
                    break;

                case "2":
                    NetworkCommunication.SendPatients(client, patients);
                    break;
                }
            }
        }
Example #12
0
 public ServerClient(TcpClient client, ServerApplication server, SslStream stream)
 {
     this.server = server;
     this.stream = stream;
     if (client != null)
     {
         new Thread(() =>
         {
             while (client.Connected)
             {
                 Packet packet = NetworkCommunication.ReadPacket(stream);
                 if (packet != null)
                 {
                     Console.WriteLine("recieved packet");
                     packet.handleServerSide(this);
                 }
             }
             //When disconnected:
             server.ConnectedClients.Remove(this);
             Console.WriteLine("Client disconnected");
         }).Start();
     }
 }
 /// <summary>
 /// Check if username and password are correct and send a response.</summary>
 /// <param name="username">The username of the user</param>
 /// <param name="password">The password of the user</param>
 public void Login(string username, string password)
 {
     Console.WriteLine("Iemand probeert in te loggen als " + username + ", wachtwoord: " + password);
     //Actual login checking:
     foreach (User user in server.users)
     {
         if (user.username.ToLower().Equals(username.ToLower()))
         {
             if (PasswordHash.ValidatePassword(password, user.password))
             {
                 NetworkCommunication.SendPacket(new PacketLoginResponse(true, user.accessRights), stream);
                 Console.WriteLine("{0} succesfully logged in.", username);
                 this.user = user;
                 break;
             }
             else //wrong password
             {
                 Console.WriteLine("wrong password");
                 NetworkCommunication.SendPacket(new PacketLoginResponse(false, user.accessRights), stream);
                 break;
             }
         }
     }
 }
Example #14
0
 public void RequestData()
 {
     NetworkCommunication.WriteMessage(tcpClient, "2");
 }
 public void GetUsers()
 {
     Console.WriteLine("Someone is requesting all users");
     NetworkCommunication.SendPacket(new PacketGetUsersResponse(server.users), stream);
 }
 public void GetWerkbonnen()
 {
     Console.WriteLine("Someone is requesting all werkbonnen " + server.werkbonnen.Count);
     NetworkCommunication.SendPacket(new PacketGetWerkbonnenResponse(server.werkbonnen), stream);
 }
Example #17
0
		private ICommunication CreateConnection()
		{
			ICommunication returnType = null;

			switch (ConnControl.GetConnectionType())
			{
				case ConnectionType.Bluetooth:
					returnType = new BluetoothCommunication();
					break;
				case ConnectionType.WiFi:
					returnType = new NetworkCommunication(ConnControl.GetIpAddress());
					break;
			}

			return returnType;
		}
 /// <summary>
 /// Send a packet to the server.</summary>
 /// <param name="packet">The packet that will be send</param>
 public void sendPacket(Packet packet)
 {
     NetworkCommunication.SendPacket(packet, ssl);
 }