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
Regular Contributor
vaidyanet
Posts: 69
Registered: ‎04-05-2010
My Device: Storm
My Carrier: BSNL

How to check an IP address is reachable

I want to check whether the any given IP address is reachable. Simillar to ping, however I know that blackberry does not open up to send the ICMP packets, just wondering whether any best way to do this.
Maximum I can think what I should do is
DatagramConnection _connection = Connector.open(connectURL, Connector.READ_WRITE, true);

Datagram outDatagram = connection.newDatagram(connection.getMaximumLength());
byte[] packet = {0,0};
outDatagram.setData(packet, 0, packet.length);
try
{
          connection.send(outDatagram)
}
catch( TimeoutException)
{
   // Not reachab;e
}
//Reachable

Pls suggest.

 

Please use plain text.
Regular Contributor
vaidyanet
Posts: 69
Registered: ‎04-05-2010
My Device: Storm
My Carrier: BSNL

Re: How to check an IP address is reachable

Even this solution does not seem to work. Even though I use invalid IP address, send is successful. Receive fails with timeout. However as I am not expecting any packet from the machine, I am not able to make any distinction between invalid IP and normal timeout.

 

String testmessage = "Test Package";

byte[] testBytes = testmessage.getBytes();

String connectURL = "datagram://100.100.255.234:8421;5624";

connection = (DatagramConnection) Connector.open(connectURL, Connector.READ_WRITE, true);

Datagram outDatagram = connection.newDatagram(conection.getMaximumLength());

outDatagram.setData(testBytes, 0, testBytes.length);

connection.send(outDatagram);

 

Any way to check the IP address is valid and reachable i.e exists in network.

 

 

Please use plain text.