can I make a UDP berkley socket hold only a UDP single message ? meaning it will override existing message if unread message is present when a new message arrives ?
+2
A:
The only way you could do that would be to handle it on the application side, as far as I know. I assume you have a UDP socket getting some kind of real time data and that you only care about the latest / most recent packet of data to arrive. If that's the case you could do something like the following pseudo code:
struct foo {
...
}
int get_most_recent_packet(int sockfd, struct foo *foobuf) {
ssize_t ret; int gotPacket = 0;
while ((ret = recvfrom(sockfd, foobuf, sizeof(struct foo),
MSG_DONTWAIT, NULL, NULL)) > 0) {
gotPacket = 1;
}
if (gotPacket) return 1;
return -1;
}
See the man page for recvfrom
.
Robert S. Barnes
2010-03-17 22:41:16
A:
DNS records have a random transaction ID, so that the application can match the result to the request. You might try using your own transaction ID.
Marcus Adams
2010-03-25 17:26:16