Qubeuc
Qubeuc

Reputation: 982

UDP Send Error on BlackBerry

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);
        }
    }
}

Upvotes: 1

Views: 1271

Answers (3)

kozen
kozen

Reputation: 509

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.

Upvotes: 1

roryf
roryf

Reputation: 30160

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.

Upvotes: 2

Douglas Leeder
Douglas Leeder

Reputation: 53310

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.

Upvotes: -1

Related Questions