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
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access