DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2

Hybrid View

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



Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links