Sockets

What is a socket
A way to speak to other programs using standard Unix file descriptors.

How do I handle sockets?
You make a call to the socket by using the send and recv socket calls. Can use normal read and write, but the send and recv offers a greater control of the transmission.

Stream Sockets
Realiable two-way connected communation streams.

FIFO (A,B in results in A,B out) Used by telnet applications (all characters taken as input is ordered the same in output)

Used by HTTP (uses stream sockets to get pages).

Uses TCP (The Transmission Control Policy) to achive a high level of transmission quality.

Uses IP for routing (?).

Maintains an open connection.

Stream sockets are used for reliability.

Datagram Sockets (connectionless sockets)
Unrelieable (may arrive, may arrive out of order).

If it arrives, the data within the packet will be error-free.

Uses IP for routing, but not TCP. Uses UDP (User Datagram Protocol).

Is connectionless, as it doesn't have to maintain an open connection as done with stream sockets.

Used either when TCP stack is unavailable or when a few droppet packets doesn't mean anything.

Used by multiplayer games, streaming media, etc.

Also used by TFTP (Trivial File Transfer Protocol) and DHCPCD (a DHCP client), which can't actually loose any packets. Thouch, tftp and dhcpd have their own protocol on top of UDP which ensures that this won't happen. The TFTP in example has a protocol that says that for every packet sendt, the recipient has to send a packet back which informs the sender that the packet is recieved. This packet is known as an "ACK" packet. If the ACK isn't recieved by the sender in a given time, the package is re-transmitted.

For more unreliable applications, the dropped packages are just ignored or cleverly compensated for.

Datagram sockets are used for speed.