문제

What happens when you attempt to recv from a socket into a buffer that isn't big enough to store an entire datagram? Will as much of the datagram that can be stored be recv'd? Will the rest be lost? Or will it be returned on a subsequent call to recv?

Is there a way to ensure that entire datagrams are read regardless of their size?

도움이 되었습니까?

해결책

Typically, (certianly on Windows/Linux), a datagram is truncated to fit into the passed buffer and the remaining data is lost permanently.

Is there a way to ensure that entire datagrams are read regardless of their size?

Use a 64K buffer. The UDP protocol ensures that datagrams cannot be larger than that, so all datagrams succesfully received will be read completely regardless of their size.

다른 팁

It depends on the platform. Systems that adhere to the Single Unix Specification (e.g., Linux) will truncate the datagram to fit and discard the remainder.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top