views:

320

answers:

1

A friend and I are working on a project where we're required to build a reliable UDPclient/server using VB.Net. We have things working well, but one thing that still eludes us is how to dynamically allocate a (byte) buffer for the incoming data. Right now we have to hard code a maximum value/MTU (or use a really large buffer size and resize it once we've finished receiving). Does anyone know of a way that this can be done without needing to specify the receive buffer size?

Basically, before calling the receive function on the socket with a buffer of size x, we want to know x so we can allocate an appropriately sized buffer. Perhaps this is a problem in all socket programing that you just have to deal with??

Thanks for any and all help (if any clarity is required, please let me know)

+1  A: 

This is one of the burden's you'll have to take on when you use UDP. You'll have to consider Path MTU discovery. Then again, since you are making reliable UDP, you should be able to auto-detect this and dynamically switch to a smaller packet size. That will solve PMTUD problems as well.

Hopefully, this doesn't sound too much like: "those whose don't use TCP are doomed to reinvent it." Check out the RFCs that are linked in that article for ideas.

Hans Passant
Thanks for the answer. I have read the Path MTU discovery RFC and it's something we may look at implementing in the future. We may just go with the maximum packet size set out by the Socket which looks to be 8k. If TCP were an option we'd be using it for sure, but you really learn to respect the guys that built these protocols initially (when you try to rebuild them yourselves)
newfie_coder