Stats

68 Contributors: 1 Tuesday, May 9, 2017
Licensed under: CC-BY-SA
Not affiliated with Stack Overflow
Rip Tutorial: riptutorial@gmail.com
Roadmap: roadmap

Java Sockets

Introduction

Sockets are a low-level network interface that helps in creating a connection between two program mainly clients which may or may not be running on the same machine.

Socket Programming is one of the most widely used networking concepts.

Remarks

There are two types of Internet Protocol Traffic -
1. TCP - Transmission Control Protocol 2. UDP - User Datagram Protocol

TCP is a connection-oriented protocol.
UDP is a connectionless protocol.

TCP is suited for applications that require high reliability, and transmission time is relatively less critical.

UDP is suitable for applications that need fast, efficient transmission, such as games. UDP's stateless nature is also useful for servers that answer small queries from huge numbers of clients.

In simpler words -
Use TCP when you cannot afford to loose data and when time to send and receive data doesn't matter. Use UDP when you cannot afford to loose time and when loss of data doesn't matter.

There is an absolute guarantee that the data transferred remains intact and arrives in the same order in which it was sent in case of TCP.
whereas there is no guarantee that the messages or packets sent would reach at all in UDP.

Related Examples