CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2003
    Location
    india
    Posts
    1

    Exclamation connecting multiple clients to a server using java

    friends

    i am doing a project in java,is it possible to connect multiple clints in a lan to a server using java,please explain how

  2. #2
    Join Date
    Mar 2002
    Posts
    132
    There are multiple ways u can achieve ur objectives using java. Ur choice depends upon ur requirement
    1. RMI This is 100% java solution. u will not be depending on any other technology.
    2. EJB (Application Server will also be needed)In this user will can either have html/java frame interface. EJB's are bit complicated technology.
    3. Servlets/JSP(WebServer will be needed). In this user's will be viewing html interface. whereas at the server servlets/jsp will be running. This is fastest to implement.

    u can see java.sun.com for tutorial on respective technologies

    saddysan

  3. #3
    Join Date
    Jan 2002
    Location
    Halifax, NS, Canada
    Posts
    985
    Are you talking about a Client/Server application?

    I'm not sure how to explain it, but you have a ServerSocket listening on your server, when a connection is made, you send the connection to a new socket object on a new thread, then your ServerSocket would continue listening.

    I would use a Inner Class that Extends Thread, in the Constructor, you would pass your Accepted Socket. ie

    Code:
       // above in a method somewhere
       mySocketThread = new SocketThread(myServerSocket.accept());
       mySocketThread.start();
    
    
    
       // inner Class, For lack of a better name
       class SocketThread extends Thread   {
          Socket socConnection;
          public SocketThread(Socket s)   {
             socConnection= s;
          }
          public void run()   {
              // start communicating
          }
       }
    I don't know for sure if this would work, with Java I've only worked with sockets for peer-to-peer purposes. Although I have gotn' a VB program to work with multible connections, but I had an array of sockets.
    Last edited by Goodz13; January 25th, 2003 at 12:44 PM.

  4. #4
    Join Date
    Jun 2002
    Location
    Sweden
    Posts
    136
    Indeed the most simple solution is the latest reply, with a main thread recieving client connections, and then passing that new socket on to a new thread in the server program.

    My final project in programming classes (low grade, but ah well) was writing a chat-client/server. It worked perfectly with multiple clients handled by multiple threads in the serverprog.

    So. Yes. It works.
    Captain Obvious

    Documentation is your friend

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured