|
-
January 25th, 2003, 02:36 AM
#1
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
-
January 25th, 2003, 05:54 AM
#2
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
-
January 25th, 2003, 12:41 PM
#3
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.
-
January 25th, 2003, 06:29 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|