Port number is 0 system randomly assigned ports, connection queue system generally default 50, refers to more than the system is the largest system-based
//If the client's connection exceeds the connection queue, it will be rejected by the host
ServerSocket serversocket=new ServerSocket (3344,20);
//refers to which IP is listening on this machine
ServerSocket serversocket=new ServerSocket (3344, Inetaddress.getbyname ("localhost"));
ServerSocket serversocket=new ServerSocket ();
//ETC Client connection time-out, unit MS, default 0 does not time out
Serversocket.setsotimeout (1000);
//Bind a port, which is used primarily for non-parameter objects, set the ServerSocket property before the Bind method
Serversocket.bind (New Inetsocketaddress (3344));
//Blocking program, waiting for client connection, this socket close does not shut down ServerSocket
Socket socket= serversocket.accept ();
try {
if (serversocket!=null) {
//serversocket Close the associated socket after closing
Serversocket.close ();
}
} catch (Exception e) {
}
//Gets the bound IP, and if there are multiple NICs, randomly returns one of the
System.out.println (Serversocket.getinetaddress ());
//Determine if ServerSocket has bound a port
System.out.println (Serversocket.isbound ());
//Determine if the ServerSocket is closed and returns false if no ports are bound
System.out.println (serversocket.isclosed ());
//correctly determine if the ServerSocket is open
System.out.println (Serversocket.isbound () &&!serversocket.isclosed ());
Java Network Programming 4-serversocket