O'Reilly logo

J2EE™ and Beyond: Design, Develop, and Deploy World-Class Java™ Software by Art Taylor

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required