Client/Server Message Routing
I have a client/server application thatis very similar to a chat program where
the SERVER will need to send messages to a specific CLIENT.
The problem is that I do not know how to get an ID or THREAD ID for the ClientWorker
class after it is started.
IF you have any tips I would appreciate it!
Thanks,
Keith
HEre is my code so far:
package multiserver;
import java.net.*;
import java.io.*;
import java.lang.String;
class ClientWorker implements Runnable
{
public ClientWorker (Socket socket){
System.out.println("You are now in CLIENT WORKER");
}
public void run()
{
}
}
public class MultiServer {
boolean serverListening = true;
ServerSocket serverSocket = null;
public MultiServer() {
System.out.println("Starting Khrondar Multicast Server..");
// Start Server, obtain PORT, obtain INET Address //
try {
serverSocket = new ServerSocket(4444);
System.out.println("PORT resolved at [" + serverSocket.getLocalPort()
+ "]");
System.out.println("INET address resolved at [" + serverSocket.getInetAddress()
+ "]");
} catch (IOException e) {
System.err.println("Khrondar Multicast Server could not listen
on port: 4444.");
System.exit(-1);
}
System.out.println("Khrondar Multicast Server instantiated.");
System.out.println("Starting Khrondar Multicast Socket Listener.");
// SOCKET LISTENER //
while (serverListening)
{
try {
new ClientWorker(serverSocket.accept());
} catch (IOException io) {
io.printStackTrace();
}
}
}
public static void main(String[] args) {
MultiServer server = new MultiServer();
}
}
Re: Client/Server Message Routing
hi ,
Why cant u use the thread .getName() to check whether r u getting a unique
name for each thread or use UUID algorithm to generate an unique id and
set the Thread's name to this id using Thread.setName().Lemme know if this
finds u in comfort
cheers,
Murugan
"Keith Derington" <keith.derington@archangelstudio.net> wrote:
>
>I have a client/server application thatis very similar to a chat program
where
>the SERVER will need to send messages to a specific CLIENT.
>
>The problem is that I do not know how to get an ID or THREAD ID for the
ClientWorker
>class after it is started.
>
>IF you have any tips I would appreciate it!
>
>Thanks,
>
>Keith
>
>HEre is my code so far:
>
>package multiserver;
>
>import java.net.*;
>import java.io.*;
>import java.lang.String;
>
>class ClientWorker implements Runnable
>{
> public ClientWorker (Socket socket){
> System.out.println("You are now in CLIENT WORKER");
>
> }
>
> public void run()
> {
>
> }
>}
>
>public class MultiServer {
> boolean serverListening = true;
> ServerSocket serverSocket = null;
>
> public MultiServer() {
> System.out.println("Starting Khrondar Multicast Server..");
> // Start Server, obtain PORT, obtain INET Address //
> try {
> serverSocket = new ServerSocket(4444);
> System.out.println("PORT resolved at [" + serverSocket.getLocalPort()
>+ "]");
> System.out.println("INET address resolved at [" + serverSocket.getInetAddress()
>+ "]");
> } catch (IOException e) {
> System.err.println("Khrondar Multicast Server could not listen
>on port: 4444.");
> System.exit(-1);
> }
>
> System.out.println("Khrondar Multicast Server instantiated.");
> System.out.println("Starting Khrondar Multicast Socket Listener.");
>
> // SOCKET LISTENER //
> while (serverListening)
> {
> try {
> new ClientWorker(serverSocket.accept());
> } catch (IOException io) {
> io.printStackTrace();
> }
> }
> }
> public static void main(String[] args) {
> MultiServer server = new MultiServer();
> }
>}
>
>