Is it possible to access the buffer of a DatagramSocket in Java

Question!

I have a DatagramSocket, and I know that socket.receive() has a buffer that stores packets that have been sent to the socket. I am trying to implement a reliable protocol using UDP, and it would be ideal if, after my window is full, I could unload the buffer all at once. If i did a simple loop, when the buffer is empty the socket.receive() would block my program, which I do not want.

Is there any way to access that buffer?

By : bronzeson


Answers

DatagramSocket has no buffer. The network stack in your operating system has a buffer, but you cannot access it.

I am trying to implement a reliable protocol using UDP

I would advice not to do that - you'll end up inventing TCP, but with bugs of your own.

By : Joni


No, but there is DatagramChannel in non-blocking mode.

By : EJP


Sounds like a certain networks assignment due tonight...

There's no real way to unload all the packets at once. I would recommend instead setting the socket to timeout after a small period (smaller than the total timeout value the sender has), and looping through sending packets in your window and receiving acknowledgements.



This video can help you solving your question :)
By: admin