Client/Server Message Routing


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Client/Server Message Routing

  1. #1
    Keith Derington Guest

    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();
    }
    }



  2. #2
    murugan Guest

    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();
    > }
    >}
    >
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center