Source Code : Server allows connections on socket 6123

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Server allows connections on socket 6123

Server allows connections on socket 6123
  
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;

public class SocketDemo {
  public static void main(String[] args) {
    try {
      ServerSocket server = new ServerSocket(6123);
      while (true) {
        System.out.println("Listening");
        Socket sock = server.accept();
        InetAddress addr = sock.getInetAddress();
        System.out.println("Connection made to " + addr.getHostName()
            + " (" + addr.getHostAddress() + ")");
        pause(5000);
        sock.close();
      }
    } catch (IOException e) {
      System.out.println("Exception detected: " + e);
    }
  }

  private static void pause(int ms) {
    try {
      Thread.sleep(ms);
    } catch (InterruptedException e) {
    }
  }
}
           
         
    
  

Thank with us