0

I have created a server socket with port 4242 but, It is getting timed out. serversock.accept() takes very long time to execute. Please advice.

ServerSocket serversock= new ServerSocket(4242);

System.out.println("Waiting " + serversock.getLocalPort() + "...");

Socket socket = serversock.accept();

System.out.println("Just connected to "  + serversock.getLocalSocketAddress());
1
  • 2
    accept() waits for clients to connect. As long as there are no clients, it will block. Commented Dec 8, 2013 at 16:24

2 Answers 2

1

Your code looks ok. You must run it, and then try to connect to your 4242 port in order for your program to proceed to the println instruction. accept() blocks until a connection is made.

Sign up to request clarification or add additional context in comments.

Comments

0

Here is a good Tutorial how to handle ServerSockets and (Client)Sockets.

There you can see how your problem can be solved by accessing the port 8080 with your browser without another Java programm.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.