Stateless sockets

There are two common stateless protocols: UDP and ICMP.

 

Each socket of this protocol can both send and receive. (unlike TCP sockets)

 

UDP

 

UDP has two options of communicating:

 

Explicit binding

The user binds its socket to an address and port, and receives all the UDP packets sent to that address and port.

 

The socket can send data to whatever address he chooses.

No binding

After the user sent the first UDP packet, the OS implicitly binds the socket to that address.

 

For instance someone sent a UDP packet to it's UDP server (port 53, and from OS assigned port 2001)

The OS will bind this socket to the relevant  network interface and port 2001, to be able to accept reply from that address.

 

ICMP

 

ICMP sockets works just like UDP, except that ICMP has no ports.

For that reason the OS can sometimes give to the user "wrong" packets.

 

Make sure you check each packet you receive that you expected it (like for ICMP echo check the identifier and sequence that they match what you sent)