Code example for ServerSocket

Methods: setReuseAddresssetSoTimeout

		services = new HashMap<String, Map<String, RPCCallableMethod>>();
		String configServerPort = OS.config().getProperty("rpc.serverport");
		int serverport = 0;
		if (!configServerPort.isEmpty())
			serverport = Integer.parseInt(OS.config().getProperty("rpc.serverport"));
		mServerSocket = new ServerSocket(serverport);
		String RPCTimeout= OS.config().getProperty("rpc.timeout");
		this.rpcTimeout = 5000;
		try { 
			this.rpcTimeout = Integer.parseInt(RPCTimeout);
		} catch (Exception e) {
		// Set some socket options.   
		// setReuseAddress lets you reuse a server port immediately after terminating 
		// an application that has used it.  (Normally that port is unavailable for a while, for reasons we'll see 
		// later in the course. 
		// setSoTimeout causes a thread waiting for connections to timeout, instead of waiting forever, if no connection 
		// is made before the timeout interval expires.  (You don't have to use 1/2 sec. for this value - choose your own.) 
		mServerSocket.setReuseAddress(true); // allow port number to be reused immediately after close of this socket
		mServerSocket.setSoTimeout(10000); // well, we have to wake up every once and a while to check for program termination
		server = new Server(mServerSocket);
Contextual code suggestions in your IDE  Get Codota for Java