Java Sockets
Two classes are generally used to create socket connections using Java: java.net.Socket and java.net.ServerSocket. The server application uses an instance of the ServerSocket class, and the client application uses an instance of the Socket class.
The ServerSocket is created first, identifying a port number where the server will listen for a connection. The ServerSocket will only listen for a connection on the host server where it is running.
The client application creates a Socket class instance, which accepts a combination of a host name or IP address and a port number as arguments to the constructor. If a successful connection is made, then an instance of the Socket class is created. This instance is then used to retrieve an
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access