1

I have a question considering udp packet life/route. I have a simple client server UDP scheme with a send call in the client side and a receive call in the server side. Lets say the send method gets called and the packet actually arrives in the other side BUT the server's code execution hasn't yet reached the receive method call. What happens with the packet in that time . Now i tried to stop the execution before the receive call with a simple command input prompt , waited a little and then let it continue and noticed that the packet got received . Can you explain WHY that happen, like is it buffered on a different OSI level?

Thanks in advance.

user2788573
  • 99
  • 1
  • 7

2 Answers2

1

Every TCP or UDP socket has a send buffer and a receive buffer. Your datagram got queued into the send buffer at the sender, then it got sent, then it got queued into the receive buffer at the receiver, then you read it from there.

NB has nothing to do with it. TCP/IP doesn't obey the OSI model. It has its own, prior model.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • This is assuming he's already set up the `DatagramSocket` (i.e. `DatagramSocket server = new DatagramSocket(port)`, which I suppose he already has in which case there should be a receive buffer as you stated. – Jared Mar 30 '14 at 00:10
  • 1
    @Jared Obviously. If he hadn't created the socket the data wouldn't get queued anywhere and the question wouldn't exist. Re your own somewhat speculative answer, UDP would get an interrupt from the NIC, pull the data out, see that it was for a non-existent port, throw it away, and issue an ICMP error message. – user207421 Mar 30 '14 at 00:40
0

The "receive" method call doesn't receive the packet. If there's a UDP socket "open" for that port, it means that there is buffer space allocated, and that's where the NIC+OS put the data. When you call "receive", it just looks there, and if there's anything there, then it pretends to have just received it.

I should add that if the buffer is empty, then the receive call does go into a blocking state, waiting to get notified by the OS that something has arrived.

cpurdy
  • 1,177
  • 5
  • 12