Click to See Complete Forum and Search --> : problem on serversocket


dummyagain
March 13th, 2005, 11:14 AM
try{
ServerSocket ss = new ServerSocket(5011);
while (true){
System.out.println("cde");
s = ss.accept(); //get problems
System.out.println("abc");
................

it can only print the cde but not abc
so i think there is a problem in the s = ss.accept();

what shall i do to solve it?

Thank you

Joe Nellis
March 13th, 2005, 11:56 AM
As it says in the documentation, the accept method BLOCKS the current thread until it gets a connection from an outside source to that port. Look at the setSoTimeout method to set a timeout for how long it waits for a connection.

cma
March 13th, 2005, 02:36 PM
Open a connection to port 5011 such as by using telnet:

(assuming that code is run on the same machine)
telnet localhost 5011