sdgfsdh
sdgfsdh

Reputation: 37045

In Java, what happens if I leave DatagramPackets at the DatagramSocket?

I am building a networked application using DatagramSocket.

I have a "network" thread whose sole job is to pull DatagramPacket objects from a DatagramSocket and place the data on a BlockingQueue. It does this as fast as it is able. The queue is then consumed by other threads.

Suppose my "network" thread is running slow and packets are building up at the socket.

Upvotes: 2

Views: 102

Answers (1)

user207421
user207421

Reputation: 310909

Is it possible for the socket to "overflow"

It is possible for your socket receive buffer to fill to the point where no new datagrams can be accepted.

and packets get lost?

It is always possible for [UDP] packets to get lost, but yes this is another reason.

Is there any advantage to taking packets from the socket and storing them in a POJO queue early?

Not really. You're just moving the problem, from needing potentially infinite network and socket receive buffer capacity to needing potentially infinite input queue capacity. You should aim just to processs incoming datagrams as fast as you possibly can, and wear the losses however you may.

Is my "network" thread and queue setup really necessary - should I just work with DatagramSocket directly?

Yep.

Upvotes: 4

Related Questions