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

3 回答 3

2

从开发人员的角度来看,黑莓上的网络访问远非无缝。您必须在 URL 中指定应如何建立连接,或者设备必须在选项 > 高级选项 > TCP 设置中具有正确的 APN 设置。您可以尝试找到这些并输入它们以查看它是否有效。

于 2009-01-20T18:30:46.257 回答
1

UDP 要求 APN 设置在Connector.open()

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

有关这方面的更多信息,请查看连接器

它在没有 APN 的模拟器上运行良好,因为模拟器没有 APN,但您需要在真实设备上。

于 2009-04-30T16:15:52.723 回答
-1

我能想到两种可能:

  1. UDPoptionalJ2ME 规范中——所以也许黑莓不支持它。
  2. 设备所在的网络可能不支持,设备可以检测到,并报异常。
于 2009-01-18T22:07:33.277 回答