Socket socket = new socket ("168.160.12.42", 9998);
Or:
Socket Socket = new Socket(inet address . getlocalhost(),5678); //Apply to connect to the server with the host name InetAddress.getLocalHost ().
The client must know the IP address of the server, and Java also provides the related class InetAddress. An instance of this object must be provided through its static method, which mainly provides a method to obtain the local IP and InetAddress directly by name or IP.
in = new buffered reader(new InputStreamReader(socket . getinputstream()));
out = new PrintWriter(socket . get output stream(),true);
The above program code establishes a Socket object, which is connected to a server object with an ip address of168.160.12.42 and a port of 9998. And establish an input stream and an output stream, which correspond to the output of the server and the writing of the client respectively.