Socket Programming

The term socket might sound a little strange, but sockets are the objects that let you communicate with the network. A socket doesn't represent a physical device, just an endpoint of a network connection. There are three main socket classes in Java—Socket, ServerSocket, and DatagramSocket. Of these, only the Socket and ServerSocket classes are used for connection-oriented data (that is, they support the TCP protocol). The DatagramSocket class does connectionless networking (the UDP protocol).

Creating a Server

Remember from Chapter 26, "Networks and Network Protocols," that to create a TCP connection, you must first have a listener. The ServerSocket class lets you listen for incoming connections. You create a ServerSocket

Get Special Edition Using Java™ 2 Enterprise Edition 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.