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
Developer
bmlahcen
Posts: 22
Registered: ‎09-14-2009
My Device: Not Specified
Accepted Solution

Openning UDP in server mode throws IOException:null

Hi all;

i am having a problem to open a DatagramConnectionBase and UDPDatagramConnection over wifi on the device (i am using 8320 4.5.0.124)

and i get IOException with the message "null"

bu it works on the simulator (8320 4.5.0.81 and 4.5.0.102 and on 9000 os 5.0)  but not on simultor 8320 os 4.5.0.37

 

i tested all the following urls

 

     1 "datagram://:1111"
     2 "datagram://:1111;deviceside=true"
     3 "datagram://:1111;deviceside=false"
     4 "datagram://:1111;interface=wifi"
     5 "datagram://:1111;interface=wifi;deviceside=true"
     6 "datagram://:1111;interface=wifi;deviceside=false"
     7 "udp://:1111"
     8 "udp://:1111;deviceside=true"
     9 "udp://:1111;deviceside=false"
     10 "udp://:1111;interface=wifi"
     11 "udp://:1111;interface=wifi;deviceside=true"
     12 "udp://:1111;interface=wifi;deviceside=false"

 

with bothe

          (UDPDatagramConnection) Connector.open(url);

and 

          (DatagramConnectionBase) Connector.open(url);

 

but i always catch (Exception e): 

(e.toString()+":"+e.getMessage())  gives :       java.io.IOException:null 

 

 

at least url 1 and 7 work well on the simulator

 

Any Solution 

 

Please use plain text.
Developer
Posts: 1,474
Registered: ‎04-14-2009
My Device: Not Specified

Re: Openning UDP in server mode throws IOException:null

UDP only works (well/at all) on handheld software v4.5.0.83+.
Please use plain text.
Developer
bmlahcen
Posts: 22
Registered: ‎09-14-2009
My Device: Not Specified

Re: Openning UDP in server mode throws IOException:null

I know that there was a bug fixed in 4.5.0.83+

but i said i am using 4.5.0.124

Please use plain text.
Developer
Posts: 1,474
Registered: ‎04-14-2009
My Device: Not Specified

Re: Openning UDP in server mode throws IOException:null

Sorry, I misread v4.5.0.37 as the version of your handheld software.

 

Since you want to listen on the WLAN interface, you need to use the interface=wifi URL parameter.

 

The following demo code works fine on my Pearl 8120 (EDGE, Wi-Fi) v4.5.0.124 (Platform 2.7.0.92), on a Curve 8900 (EDGE, Wi-Fi) v4.6.1.231 (Platform 4.2.0.108), and also on a Bold 9000:

 

 

UDPDatagramConnection connection = null; try { logInfo("Opening UDP socket"); connection = (UDPDatagramConnection) Connector.open("udp://:1111/;interface=wifi"); logInfo("Listening on UDP socket: " + connection.getLocalAddress() + ":" + connection.getLocalPort()); final Datagram datagram = connection.newDatagram(1500); while (true) { connection.receive(datagram); final String text = new String(datagram.getData(), datagram.getOffset(), datagram.getLength()); logInfo("Received " + datagram.getLength() + " bytes: \"" + text + "\""); if (text.toLowerCase().startsWith("exit")) { break; } } logInfo("Done listening"); } catch (Throwable e) { logError("Failed to listen: " + e); } finally { if (connection != null) { try { logInfo("Closing UDP socket"); connection.close(); } catch (IOException e) {} } }

 

 

 

Please use plain text.
Developer
bmlahcen
Posts: 22
Registered: ‎09-14-2009
My Device: Not Specified

Re: Openning UDP in server mode throws IOException:null

Thank for your answer

 

i will test it later on the device and report the result,(it works on the simulator)

 

but what is that "/" after the port number, it does not confirm to syntax given in the API docmentation of UDPDatagramConnection

 

 

Please use plain text.
Developer
Posts: 1,474
Registered: ‎04-14-2009
My Device: Not Specified

Re: Openning UDP in server mode throws IOException:null

The "/" after the port number(s) and before any name-value pairs is required according to the javadocs of Connector.open (see UDP subsection: e.g., http://www.blackberry.com/developers/docs/4.6.0api/javax/microedition/io/Connector.html#udp).

Please use plain text.
Developer
bmlahcen
Posts: 22
Registered: ‎09-14-2009
My Device: Not Specified

Re: Openning UDP in server mode throws IOException:null

Hi,

i am really very dispointed as it did not work for me and i am really in hurry to finish this,

my client has been waiting for long time and i have disturbed him by always sending tests that does not work

 

Even adding "/" after the port number did not work for me

 

i used : url="datagram://:1111/;interface=wifi"   and   url="udp://:1111;interface=wifi"  with 

socket = (DatagramConnectionBase) Connector.open(url);

and also socket = (UDPDatagramConnection) Connector.open(url); 

 

but none of them has worked i get: java.io.IOException:null

 

is there any configuration or other thing to do, to check or change?

 

Please use plain text.
Developer
Posts: 1,474
Registered: ‎04-14-2009
My Device: Not Specified

Re: Openning UDP in server mode throws IOException:null

1. Check whether the handheld software version on this device is v4.5.0.83+ (although you'd said it is, check again, just in case -- the java.io.IOException: null is usually an indicator that UDP doesn't work on the device).

2. Check whether this device can connect via WiFi at all.

3. Check whether WiFi is on and connected to a WLAN.

4. Check whether this code works on the cellular interface (remove the interface=wifi parameter) -- it does on all my test devices.

Please use plain text.
Developer
bmlahcen
Posts: 22
Registered: ‎09-14-2009
My Device: Not Specified

Re: Openning UDP in server mode throws IOException:null

Thanks for your help.

I found out that my Ant compiling tool was using JDE 5.0.0 while i was using 4.5.0 for testing.

The compiled .cod file works on the simulator but not in the device, it runs, but does not open the datagram connection.

I set the Ant tool to use JDE 4.5.0 and every thing worked well.

However i am having a an Exception in sending packet, i put it in another post

 

Please use plain text.