msj121
msj121

Reputation: 2842

ICE4J DatagramPacket too small

Regular DatagramSocket works fine... ICE4J DatagramSocket seems to truncate data!?

The sending size packet is 2,500 but the receiving end is always 1500 (with regular Java DatagramSocket the receive packet size is the same as the send size).

Receive End:

 Component rtpComponent = stream.getComponent(org.ice4j.ice.Component.RTCP);
 CandidatePair rtpPair = rtpComponent.getSelectedPair();
 videoDS = rtpPair.getDatagramSocket();

In a Thread:

byte[] buffer = new byte[250000000];
final DatagramPacket dp = new DatagramPacket(buffer, buffer.length);
videoDS.receive(dp);
final byte[] clone = new byte[dp.getLength()];
System.arraycopy(dp.getData(), dp.getOffset(), clone, 0, dp.getLength());
final Image image = new Image(new ByteArrayInputStream(clone));

The sending side is pretty much the same except it is run on an Android...

The only difference between non-working code is that the first paragraph is used for Sending and Receiving. If I use a regular Java Socket it will work (but of course not behind routers, which is why I am using Ice4J).

Upvotes: 1

Views: 362

Answers (2)

msj121
msj121

Reputation: 2842

I found the prime issue....

See org.ice4j.stack.Connector line 160

/*
* Make sure localSock's receiveBufferSize is taken into
* account including after it gets changed.
*/
int receiveBufferSize = 1500;

The data is CLEARLY being cutoff.... see line 188

packet.setData(
            new byte[receiveBufferSize],
            0,
            receiveBufferSize);
....
localSock.receive(packet); //line 200

My Current solution is to edit the receiveBufferSize to 25000 and the actual packet data is the correct amount. Perhaps I will request to merge.

Upvotes: 1

user207421
user207421

Reputation: 310909

The sending size packet is 25,000 but the receiving end is always 1500

You are never going to receive a UDP datagram larger than the path MTU unless:

  • there is no router between you and the target, and/or
  • the datagram didn't get fragmented, or
  • all the fragments arrived at the target.

Otherwise loss of any fragment leads to loss of the entire datagram.

The generally accepted payload limit for UDP datagrams is 534 bytes. Not 25k.

Upvotes: 0

Related Questions