This tutorial is an introduction to socket programming Java, starting with a simple client-server example demonstrating the basic features of Java I/O. You’ll be introduced to both the original
java.iopackage and NIO, the non-blocking I/O (java.nio) APIs introduced in Java 1.4. Finally, you’ll see an example that demonstrates Java networking as implemented from Java 7 forward, in NIO.2.
Socket programming boils down to two systems communicating with one another. Generally, network communication comes in two flavors: Transport Control Protocol (TCP) and User Datagram Protocol (UDP). TCP and UDP are used for different purposes and both have unique constraints:

