Listening to multiple clients.

how do it make a server listen to multiple clients and process them.so far i have reached just thiswhile(true)socket=serversocket.accept();but what after this.how to handle separate each client........
[236 byte] By [psychica] at [2007-11-26 18:36:15]
# 1
If you're going to listen for incoming data, you need a separate thread for each spawned Socket coming from your server socket.
tjacobs01a at 2007-7-9 6:10:17 > top of Java-index,Java Essentials,Java Programming...
# 2

> how do it make a server listen to multiple clients

> and process them.

>

> so far i have reached just this

>

> while(true)

> socket=serversocket.accept();

>

> but what after this.how to handle separate each

> client........

For threading go through this

http://java.sun.com/docs/books/tutorial/essential/concurrency/

> while(true)

> socket=serversocket.accept();

You have to start a new thread for each client and then do the needful.

Say you can implement two different threads to handle the messages to be sent and the messages to be received. Get the required inputstream and outputstream for the socket and use it in each thread.

like

BufferedReader in=new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));

PrintWriter out=new PrintWriter(clientSocket.getOutputStream(),true);

qUesT_foR_knOwLeDgea at 2007-7-9 6:10:17 > top of Java-index,Java Essentials,Java Programming...
# 3
> If you're going to listen for incoming data, you need> a separate thread for each spawned Socket coming from> your server socket.thanks a lot.will give it try
psychica at 2007-7-9 6:10:17 > top of Java-index,Java Essentials,Java Programming...