Click to See Complete Forum and Search --> : connecting multiple clients to a server using java
chitrask
January 25th, 2003, 01:36 AM
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
saddysans
January 25th, 2003, 04:54 AM
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
Goodz13
January 25th, 2003, 11:41 AM
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
// 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.
Metaphor
January 25th, 2003, 05:29 PM
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.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.