tags:

views:

297

answers:

2

Hello , I am sending packets from one pc to other. I am using python socket socket.socket(socket.AF_INET, socket.SOCK_DGRAM ). Do we need to take care of order in which packets are received ? In ISO-OSI model layers below transport layer handle all packets communication. Do all ISO-OSI layers present in the program ? Or some of them present in operating system ? On localhost I get all packets in order. Will it make any difference over internet ?

+4  A: 

SOCK_DGRAM means you want to send packets by UDP -- no order guarantee, no guarantee of reception, no guarantee of lack of repetition. SOCK_STREAM would imply TCP -- no packet boundary guarantee, but (unless the connection's dropped;-) guarantee of order, reception, and no duplication. TCP/IP, the networking model that won the heart and soul of every live practitioned and made the Internet happen, is not compliant to ISO/OSI -- a standard designed at the drafting table and never really winning in the real world.

The Internet as she lives and breathes is TCP/IP all the way. Don't rely on tests done on a low-latency local network as in ANY way representative of what will happen out there in the real world. Welcome to the real world, BTW, and, good luck (you'll need some!-).

Alex Martelli
+2  A: 

To answer your immediate question, if you're using *SOCK_STREAM*, then you're actually using TCP, which is an implementation of the transport layer which does take care of packet ordering and integrity for you. So it sounds like that's what you want to use. *SOCK_DGRAM* is actually UDP, which doesn't take care of any integrity for you.

Do we need to take care of order in which packets are received ? In ISO-OSI model layers below transport layer handle all packets communication. Do all ISO-OSI layers present in the program ?

Just to clear this up, in the ISO-OSI model, all the layers below the transport layer handle sending of a single packet from one computer to the other, and don't "understand" the concept of packet ordering (it doesn't apply to them).

In this model, there is another layer (the session layer, above the transport layer) which is responsible for defining the session behavior. It is this layer which decides whether to have things put in place to prevent reordering, to ensure integrity, and so on.

In the modern world, the ISO-OSI model is more of an idealistic template, rather than an actual model. TCP/IP is the actual implementation which is used almost everywhere.

In TCP/IP, the transport layer is the one that has the role of defining whether there is any session behavior or not.

Edan Maor