multithreadTCP sever problem

I am currently coding a multithread TCP server , its very , very basic and offers two services depending on which client it is , one service modifies a sentence sent by the client, and changes into capital letters. The other services counts the total length of the string and returns this to the client. My problem is getting the server to recognize which client is sending the message, the only way i have managed to do this so far is by using modulus to determine if the client is even or odd and offer 1 service to the connected clients which are odd and the other service to the even numbered clients. What i need is some way of identifying which client is connecting to the server, below is the code for a client connecting to my server.

do{

Socket client = welcomeSocket.accept();

System.out.println("\nNew client accepted.\n");

//Create a thread to handle communication with

//this client and pass the constructor for this

//thread a reference to the relevant socket...

TCPMultiThreadServer.ClientHandler handler =

new TCPMultiThreadServer().new ClientHandler(client,clientNo);

handler.start();//this method calls run.

clientNo++;

}while (true);

class ClientHandlerextends Thread

{

private Socket client;

private BufferedReader inFromClient;

private DataOutputStream outToClient;

publicint clientNo;

publicboolean stopping;

public ClientHandler(Socket socket,int clientNos)

{

//Set up reference to associated socket...

client = socket;

clientNo= clientNos;

try

{

inFromClient =

new BufferedReader(new

InputStreamReader(client.getInputStream()));

outToClient =

new DataOutputStream(client.getOutputStream());

}

catch(IOException e)

{}

}

and the code for the client goes along the lines of

try{

do{

System.out.print("Enter message: ");

sentence = inFromUser.readLine();

outToServer.writeBytes(sentence +'\n');

modifiedSentence = inFromServer.readLine();

System.out.println("FROM SERVER: " + modifiedSentence);

}while(!sentence.equals("CLOSE"));

}catch(IOException e)

{}

clientSocket.close();

Any hints would be appreciated.

Many Thanks

[3860 byte] By [mdrayne1a] at [2007-11-26 19:17:24]
# 1

Well, what is different about the clients?

If they can be distinguished by their IP address you can use

http://java.sun.com/j2se/1.5.0/docs/api/java/net/Socket.html#getInetAddress()

Otherwise, either the clients will have to send you something on connection to identify which service they want, or else you will have to have each service listening on a different port: so the clients for service 1 connect to one port and the clients for the other service connect to the other port.

ejpa at 2007-7-9 21:31:34 > top of Java-index,Core,Core APIs...
# 2

The only difference in the clients is that 2 of them are set up to receive a count of the length of the string sent and the other 2 are set to receive a message from the server in capitals. What i want is 2 of the clients to only get only service no matter where they connect from, same for the other 2 clients.

The different ports is something I think I am able to do, I'm not 100% sure on how to get each client to identify the service it requires with the server. However this does seem the best solution, I think i will look at how this can be implemented, I will let you know how it goes.

mdrayne1a at 2007-7-9 21:31:34 > top of Java-index,Core,Core APIs...