Have a problem I hope someone could solve for me.
I have made a server simulator and a Clint that can connect to that server simulator. My server simulator listen on some commands that my Client can send to it.
The following commands are: D, DN, S, T, B, Q
My problem is that I need to make 3 functions in the server, like u see in the menu down under: a user can enter T, B or Q in the server.
What my server should do:
So when you run the server, it asks for a connection, then you run the Client program and connect to the server via a port number.
After that the server Menu will display.
My server Menu so far.
System.out.println(" ");
System.out.println("*************************************************");
System.out.println("Welcome to Scale Simulator");
System.out.println("Netto on weight: " + (brutto-tare) + "kg");
System.out.println("*************************************************");
System.out.println(" ");
System.out.println(" ");
System.out.println("Esablished connection to address: " + sock.getInetAddress() + "");
System.out.println("Brutto on weight: " + brutto + "kg");
System.out.println(" ");
System.out.println(" ");
System.out.println("This simulator listen on the following commands: ");
System.out.println("D, DN, S, T, B, Q ");
System.out.println("Response received from Client: "+ inputRecieved + "");
System.out.println(" ");
System.out.println(" ");
System.out.println("Enter T <For Tare on weight> ");
System.out.println("Enter B - New Brutto <Enter a new brutto on weight>");
System.out.println("Enter Q <For exit the program and connection ");
System.out.print("Enter here: ");
Here I have to code it so I can enter T, B or Q, but also if I don't enter something my Client should still work so I can send a command to it like S (That will show what is on the Scale for now)
For full server code can be found here:
Hope you understand what i just wrote ;) or else tell me, and i try to explain it a bit better.
UPDATE:
So right now i read something about threads, and yes, it works, but i don't know if its the right way to code. could you please take a look:
After my client connects to the server simulator, my code is HERE:
Could you please check if this is a ok way to make the threads?
For those who don't have time to look at the pastebin ;) i done it like this:
Thread threadServer = new Thread() {
public run() {
functionality for the server functions
}
};
Thread threadClient = new Thread() {
public run() {
functionality for the Client command response functions
}
};