O'Reilly logo

Special Edition Using Java™ 2 Enterprise Edition by Mark Wutka

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

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

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