Test UDP connection on BlackBerry Simulator

I am trying to send data using UDP (datagrams). I cannot test the application on the simulator. I first tried running MDS and then the simulator, but it didn't work. The error appears as port 8080 already in use on the BlackBerry Simulator console. How do I change the port in the simulator? The UDP port I am connecting to is localhost: 5014

I am using a simulator for BlackBerry Pearl 8100.

+1


a source to share


1 answer


There are comments on the Blackberry forum about issues with datagram under 4.5.0.x to 4.5.0.83. Unsurprisingly, there are no UDP samples in sdk. You can always download 8100 using simulator 4.5.0.108 from http://na.blackberry.com/eng/developers/

Another thing is to use ip, although the hostname is allowed in the api link, but when you use the MDS simulator it grabs the localhost alias .

In the following code, you have a simple server that listens on port 135 and a client bb that sends a data packet to 127.0.0.1 on port 135.

Desktop Server Code:



public static void main(String[] args) {
    byte[] inBuff = new byte[32];
    DatagramSocket socket;
    try {
        socket = new DatagramSocket(137);
        DatagramPacket pckt = new DatagramPacket(inBuff, inBuff.length);
        while (true) {
            socket.receive(pckt);
            System.out.println(new Date() + " " + pckt.getAddress()
                    + ":" + pckt.getPort());
            socket.send(pckt);
        }
    } catch (Exception e) {
        System.out.println(e.getMessage()+":");
        System.out.println(e.getClass().getName());
    }
}

      

BlackBerry client code (tested with Bold 8900 under 4.6.1):

    UDPDatagramConnection connection = null;
    byte[] outBuff = "Hello!".getBytes();
    Datagram outDatagram = null;
    try {
        connection = (UDPDatagramConnection) Connector
                .open("datagram://127.0.0.1:137");
        outDatagram = connection.newDatagram(outBuff, outBuff.length);
        connection.send(outDatagram);
        System.out.println("Datagram packet was sent");
    } catch (Exception e) {
        System.out.println(e.getMessage()+":");
        System.out.println(e.getClass().getName());
    }

      

+4


a source







All Articles