Differences between TCP socket and UDP socket

What is socket? what are the differences between TCP socket and UDP socket.

A socket is one endpoint of a two-way communication link between two programs running on the network. A socket is bound to a port number so that the TCP layer can identify the application that data is destined to be sent.

An endpoint is a combination of an IP address and a port number. Every TCP connection can be uniquely identified by its two endpoints. That way you can have multiple connections between your host and the server.

The java.net package in the Java platform provides a class, Socket, that implements one side of a two way connection between your Java program and another program on the network. The Socket class sits on top of a platform-dependent implementation, hiding the details of any particular system from your Java program. By using the java.net.Socket class instead of relying on native code, your Java programs can communicate over the network in a platform-independent fashion.

Also View: What is servlet?

Differences between TCP socket and UDP socket

The following are the Differences between TCP socket and UDP socket

FeatureTCP (Transmission Control Protocol)UDP (User Datagram Protocol)
Full NameTransfer Control ProtocolUser Datagram Protocol
TypeConnection-oriented protocolConnection-less protocol
Used ByHTTP, HTTPS, FTP, SMTP, TelnetDNS, DHCP
SpeedSlowerFaster
ReliabilityGuaranteed delivery of dataNo guarantee of delivery
Data TransmissionStream-based; no clear separation between packetsPacket-based (Datagrams); sent independently
Order of DataEnsures data is received in orderNo guarantee of order
Header Size20 bytes8 bytes (typically)
WeightHeavyweightLightweight
AcknowledgmentHas acknowledgment segmentsNo acknowledgment
HandshakeUses handshake (e.g., SYN, SYN-ACK, ACK)No handshake