In both sides of the communication, ServerSocket is the server side responsible for receiving, it is responsible for listening to the specified port, its constructor is as follows:
1, ServerSocket () throws IOException; The parameterless constructor exists primarily because if a socket is created, its option parameter cannot be set, and the method can be used to set the parameters before specifying the port number address.
2, ServerSocket (int port) throws IOException; Specifies the listening port number, which is thrown when the port number is already occupied or because the port number is not allowed to be used for some reason.
3, ServerSocket (int port,int backlog) throws IOException; Specifies the port number of the listener and the length of the connection queue for the specified client connection request.
4, ServerSocket (int port,int backlog,inetaddress bindaddr) throws IOException; You can specify the IP address to bind.
This class of methods is:
Public inetaddress getinetaddress (): The IP address used to return the server bindings;
public int Getloalport (): This method is used to return the port number of the binding;
The class has several options that can be specified after creation:
1. So_timeout: Indicates the time to wait for the client to connect, the method is public void setsotimeout (int TIMEOUT) throws Socketexception,public int getsotimeout () Throws IOException, set in MS, if set to 0 means never time out.
2, SO_REUSEADDR: Determine whether there is data on the network to the old ServerSocket pass data when the new ServerSocket is allowed to bind to the same port as the old serversocket, public void Setresuseaddress (Boolean in) throws Socketexception,public Boolean getresuseaddress () throws Socketeception, However, be sure to use this method setting before the socket is bound to the port.
3. SO_RCVBUF: The size of the buffer that the server side uses to receive data, in bytes, publi void setreceivebuffersize (int size) throws Socketexception,public int Getreceivebuffersize () throws SocketException, which is valid after the ServerSocket is bound to the port, unless the size to be set is greater than 64KB, it needs to be set before binding.
4, public void setperformeancepreferreces (int connectiontime,int latency,int bandwidth).
Java Network Programming 2