java - Datagramsocket: how receive(...) handles fragmentation of a packet -


i came know professor that, datagram packet sent using udp socket gets fragmented in lower layers , may arrive multiple packets @ receiver end. e.g, if send 1000 bytes data in datagram packet, @ receiving end might arrive as, 2 bytes, 500 bytes, 12 bytes, , on. therefore, suggested multiple receive(...) receive entire 1000 byte packet sent sender.

later when went through java documentation datagram socket receive(...) , there line reads follows: "this method blocks until datagram received. ..." mean entire datagram packet received , don't need multiple receive (even though it's case in theory) when use java?

pls. clarify. if multiple receive(...) each packet option around problem, pls. give suggestions on how this.

any call receive() give entire packet - fragment handling happens in 2 layers below socket. fragmentation , defragmentation happens in network/internet layer (ip), socket never see fragments receive entire , full udp/tcp packets (only full packets gets sent listening port).

so, no, not need multiple receive() single packet, should aware udp not reliable if 1 fragment gets lost in network layer (and in cases if arrives out of order), won't able packet.

you might want check methods getreceivebuffersize() , setreceivebuffersize() if you're having trouble receiving packets - if buffer size smaller packet size, it's not guaranteed can receive packet.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -