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 ...
Get J2EE™ and Beyond: Design, Develop, and Deploy World-Class Java™ Software now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.