The Socket class is a basic constructor in the Java network application that implements two-way communication between programs. Socket is a communication endpoint that the user can get an input and output stream from the Socket object after a socket connection is established. To establish a Socket connection 4 ways Socket (InetAddress address, int port) Socket (InetAddress address, int port, InetAddress localAddr, int localPort) Socket (String host, int port) Socket (String host, int port, InetAddress localAddr, INT localport) Parameter Description: Address: Host address host: Host address localaddress: Local address localport: Local Port Port: Host Listening Port
The main method of the Socket class void Close () // Close Socketinetaddress getinetDress () // Gets the currently connected Internet address InputStream GetInputStream () // Gets the Socket's input stream inetdress getLocaladdress () // Get local address int getLocalPort () / / Get the local port number OutputStream getOutputStream () // Get the output stream of this socket int GETPORT (0 // Get the remote port number int getSolinger () // Get the transmission data delay time INT getsotimeout () // get The longest waiting time void setsolinger (Boolean on, int linger) // sets the connection shutdown to the longest wait time void shutdowninput () / / Close input stream void shutdownoutput () // Turns the output stream
To implement a client program, you must first know the address of the server and the listening port. Create a socket object with known addresses and ports, you can start communicating with the server.