views:

770

answers:

4

I am writing network application for Blackberry .This code is correct at simulator but not working at device. When i run my application on simulator, my server recieves the msg but when i run it on handheld, i get Exception (not IOException) that "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); } }

}

A: 

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
+1  A: 

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
A: 

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
A: 

Hi,

I am trying to send data using UDP (datagram). I am not able to test application on simulator. I tried running MDS first and then simulator,but it did not work. The error is displayed as Port 8080 already in use on BlackBerry simulator console. How do I change port in simulator? The UDP port to which I am connecting is localhost:5014

I am new to BlackBerry networking. Please help me.

Thanks.

imMobile