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

Socket Programming Example

The best way to learn the Java network API is through a demonstration. In the following example, a SocketServer instance listens for a connection, and when a connection is detected, it starts a thread to manage the connection. This is a fairly efficient method for handling connections, since incoming connection requests do not need to wait while prior connections are handled—all are, theoretically, handled at the same time.

In practice, the spawning of threads would not be open-ended and would be limited in some way to avoid overloading the system with processing. In this example, for brevity, we do not show that code.

The Server Application

The server application represents a server for order processing. As requests ...

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