Reputation: 115
I'm making a Cyber Café management software for a school project.
How can I identify each new computer (client) connected to the server? I've done the connection already but I don't know how I can identify each computer. I need to set a name or id to each client computer.
Can somebody give me example code or any suggestions? :)
ServerSocket server;
Socket client;
public void Sync() {
try {
server = new ServerSocket(35557);
System.out.println("Server started, waiting for client...");
while (true) {
System.out.println("Waiting for client...");
client = server.accept();
new Sync_procesador().start();
System.out.println("Se conecto! :D");
}
} catch (Exception ex) {
System.out.println(ex);
}
}
Upvotes: 0
Views: 222
Reputation: 718826
Judging from the comments, it seems to me that what you are really asking for is ideas on how to display the set of connected computers in a user interface. (You already knew how to identify the computer.)
My suggestion is that you just try out some simple options and see if they work. The basic idea is that you create a data structure that knows about all of the connected computers, and then you extract information (like a list of names) and display that in your UI. It is up to you to decide what to display. Possibilities include:
I'd advise trying something simple and see how effective it is. Then revise it (later on) if you have time in your project.
Upvotes: 1
Reputation: 29493
The client is already identified through the socket object you receive on behalf of server.accept()
. It really depends on what you want to do further with it. If you don't run applications using more than one port socket.getInetAddress().getHostAddress()
should be just fine.
Upvotes: 1
Reputation: 12296
you may want to get IP address of remote network card, just add
client.getInetAddress()
Upvotes: 1