6.3. TCP Sockets and Java

Java offers good support for TCP sockets, in the form of two socket classes, java.net.Socket and java.net.ServerSocket. When writing client software that connects to an existing service, the Socket class should be used. When writing server software that binds to a local port in order to provide a service, the ServerSocket class should be employed. This is different from the way a DatagramSocket works with UDP—the function of connecting to servers, and the function of accepting data from clients, is split into a separate class under TCP.

Get Java™ Network Programming and Distributed Computing 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.