Coming from a C socket()/recv() background, the Java DatagramSocket.receive API seems a bit strange. Why does force the programmer to allocate a DatagramPacket large enough for the incoming data?
Coming from a C socket() / recv() background, the Java DatagramSocket.receive API seems a
Share
This question is based on a false premise. In C, the signature for the
recvsyscall is:Note that you pass a pointer to a buffer, and the length of that buffer. The manual entry then says:
In other words, the C API expects the caller to allocate a “large enough” buffer, and may truncate messages that are longer … just like Java does.