1

I am writing network application for Blackberry. This code is correct on the simulator but not working on a device. When I run my application on the simulator, my server recieves the message but when I run it on a device, I get an Exception, not IOException, with message "NULL".

try {
     byte[] b = msg.getBytes();
     dc = (UDPDatagramConnection)Connector.open("datagram://"+getHIP()+":" + getHPort());
     Datagram dobject = dc.newDatagram(b, b.length);
     dc.send(dobject);
     System.out.println("Addr:" + dobject.getAddress());
     System.out.println("Well Done!");
} catch (IOException e) {
    System.out.println(e.getMessage());
} catch (Exception e) {
    System.out.println(e.getMessage());
} finally { 
    if (dc != null) {
        try {
            dc.close();
        } catch (Exception f) {
            System.out.println("Failed to close Connector: " + f);
        }
    }
}
Lucifer
  • 29,392
  • 25
  • 90
  • 143
Qubeuc
  • 982
  • 1
  • 11
  • 22

3 Answers3

2

Network access on the BlackBerry is far from seemless from a developer's point of view. You either have to specify how the connection should be made in the URL, or the device has to have the correct APN settings in Options > Advanced Options > TCP Settings. You could try finding those and entering them to see if it works.

roryf
  • 29,592
  • 16
  • 81
  • 103
1

UDP requires the APN to be set in the Connector.open():

(DatagramConnection) Connector.open("udp://<host>:<dest_port>[;<src_port>]/<apn>[|<type>][;tunnelauthusername=<apn username>;tunnelauthpassword=<apn password>]");

For more info on that check out the Connector

It works fine on the simulator w/o APN because the simulator doesn't have an APN, but you need on a real device.

kozen
  • 509
  • 3
  • 5
-1

I can think of two possibilities:

  1. UDP is optional in the J2ME spec - so maybe the Blackberry doesn't support it.
  2. The network the device is on might not support it, and the device can detect this, and reports it with an exception.
Douglas Leeder
  • 52,368
  • 9
  • 94
  • 137