Server allows connections on socket 6123 : Server « Network Protocol « Java






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) {
    }
  }
}
           
         
    
  








Related examples in the same category

1.A generic framework for a flexible, multi-threaded server
2.This server displays messages to a single clientThis server displays messages to a single client
3.The client can specify information to control the output of a serverThe client can specify information to control the output of a server
4.A server can use specialized streams to deliver typed dataA server can use specialized streams to deliver typed data
5.Serve entire objects using ObjectOutputStreamServe entire objects using ObjectOutputStream
6.A multithreaded serverA multithreaded server
7.Base class to build multithreaded servers easily
8.Manage a pool of threads for clients
9.Client estimates the speed of the network connection to the server
10.This server retrieves the time using the RFC867 protocol.This server retrieves the time using the RFC867 protocol.
11.Quote Server
12.Logging Server based on SocketServer
13.Client and Server Demo
14.Reflector
15.Simple Http Server