Please Help. Thank you

I am using socket connecting server and client. My problem is how to keep the server always run to accept the connection from client, which can be closed and reconnect to the server later on.Thank youMessage was edited by: Rachel2006
[261 byte] By [Rachel2006a] at [2007-11-26 13:59:14]
# 1
Continued here: http://forum.java.sun.com/thread.jspa?threadID=5120757
prometheuzza at 2007-7-8 1:39:56 > top of Java-index,Archived Forums,Socket Programming...
# 2

Hi Rachel,

I'm not exactly sure if I really understand your problem but the following code could be what you need:

ServerSocket yourSocket = new ServerSocket(80);

for(;;) {

Socket client = yourSocket.accept( );

...

...

}

Line 1just creates a new Socket with the name yourSocket on port 80(Http).

Line 2 enters an infinite loop.

Line 3 lets the socket wait for the client to connect.

Hope this solves your problem. If you need it I can also give you the full code of a little Http Server. The above is just a little piece.

Cheers,

Joerg

EDIT: I also copied this post to the other thread.

Message was edited by:

trimber

trimbera at 2007-7-8 1:39:56 > top of Java-index,Archived Forums,Socket Programming...