I use two classes in my server
Myserver.java
private ExecutorService executorService = Executors.newFixedThreadPool(10);
public static void main(String[] args) throws IOException {
server = new MyServer();
server.runServer();
}
private void runServer() {
int serverPort = 8071;
try {
System.out.println("Starting Server");
serverSocket = new ServerSocket(serverPort);
while(true) {
System.out.println("Waiting for request");
try {
Socket s = serverSocket.accept();
System.out.println("Processing request");
executorService.submit(new ServiceRequest(s));
} catch(IOException ioe) {
System.out.println("Error accepting connection");
ioe.printStackTrace();
}
}
}catch(IOException e) {
System.out.println("Error starting Server on "+serverPort);
e.printStackTrace();
}
}
and
ServiceRequest.java
private Socket socket;
BufferedReader input = null;
public ServiceRequest(Socket connection) {
this.socket = connection;
}
public void run() {
try {
//input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
DataInputStream din = new DataInputStream(socket.getInputStream());
System.out.println("Client "+ clientID +"Connected");
I want to get the number of each Client in run()
( I want to get a result in the last line of the code ). How would I do this?