Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Trouble sending UDP packets in simulator

Hello,

I'm trying to send and receive some UDP packets to manually resolve a DNS name.  The following code always gives IOException.  I tried specifying source port in addition to destination but the problem persists.  Send operation (in bold) is throwing an IOException

 

// ... having prepared data in byte[] outData, length in
// packetPos
try
{
connection = (DatagramConnection) Connector.open("udp://4.2.2.1:53/");
}
catch (IOException e)
{
return null;
}

try
{
sendPacket = connection.newDatagram(outData, outData.length);
// sendPacket.setAddress("//4.2.2.1:53/"); <--- Tried this too
sendPacket.setData(outData, 0, packetPos);
connection.send(sendPacket);
}
catch (IOException e)
{
try
{
connection.close();
}
catch (Exception e1) {}
return null;
}

 My JDE version is 4.6.0.12

 

As you can imagine, I also have some receive code later on, but it never gets to that...

 

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
Posts: 709
Registered: ‎09-10-2009
My Device: 8520, 8900, 9000, 9300, 9650, 9700, 9780, 9800, 9810, 9900, 9930
My Carrier: Verizon

Re: Trouble sending UDP packets in simulator

I believe it is datagram instead of udp.
Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Trouble sending UDP packets in simulator

No, "datagram://..." fails the same way.

 

Too bad IOException has null for detail message...

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
Posts: 1,474
Registered: ‎04-14-2009
My Device: Not Specified

Re: Trouble sending UDP packets in simulator

[ Edited ]
Try starting the receive loop in a separate thread before you attempt to send anything. Also, try a different JDE (UDP definitely works fine in JDE v4.6.1.23). I recall that some JDEs had issues with UDP. On top of it all, UDP doesn't work well prior to handheld software v4.5.0.83.
Message Edited by klyubin on 11-09-2009 05:29 PM
Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Trouble sending UDP packets in simulator

Having a prepared receiver in a separate thread did not help.  The packet is never actually sent - I checked with WireShark and it's silent (while catching the same packets from 'nslookup' aimed at the same server just fine).

 

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
Posts: 709
Registered: ‎09-10-2009
My Device: 8520, 8900, 9000, 9300, 9650, 9700, 9780, 9800, 9810, 9900, 9930
My Carrier: Verizon

Re: Trouble sending UDP packets in simulator

Are you testing on the simulator or the phone itself?
Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Trouble sending UDP packets in simulator

I'm mainly testing on the simulator but I did test on the phone once with the same result.
----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
Posts: 1,474
Registered: ‎04-14-2009
My Device: Not Specified

Re: Trouble sending UDP packets in simulator

Try creating and sending a datagram like this:

 

 

sendPacket = connection.newDatagram(outData, packetPos); connection.send(sendPacket);

 

 

 

 

 

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Trouble sending UDP packets in simulator

Tried that (creating the datagram with the correct length rather than using setData) - same result.

 

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
Posts: 1,474
Registered: ‎04-14-2009
My Device: Not Specified

Re: Trouble sending UDP packets in simulator

Try JDE v4.6.1.23 8900 simulator -- UDP definitely works for me there. On actual BlackBerrys, you need handheld software v4.5.0.83+ for UDP.