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

BlackBerry® Storm™

Reply
New Contributor
davidAU
Posts: 6
Registered: ‎03-04-2010
My Device: BlackBerry 9530 Development Simulator
Accepted Solution

UDPDatagramConnection locks up on receive()

Hello,

 

I am having a problem using UDPDatagramConnection in my BlackBerry application.  I have read a lot on the discussion boards about multi-threaded applications with UDP connections starving the main thread.  However, my situation is a little different.

 

I have a BlackBerry application that is communicating with a server.  The UDP connection all takes place in a seperate thread.  The send() function works fine for the UDPDatagramConnection.  The server sends a message back, and the UDP thread calls the receive() function.  At this point, the UDP thread hangs on the receive() function.  There is a message from the server waiting, but the receive() function locks up.

 

The ironic thing is, if I let the main thread complete, then the UDP thread can complete the receive() function call just fine.  It almost looks like the main thread is starving the UDP thread.  I have tried playing with thread priorities, join(), yield(), wait() and notifyAll(), but nothing seems to work

 

The code segment calling the UDP thread in the main program:

-----------------------------------------------------------------------------------------------

try
 {

     NetworkMessageThread blah = new NetworkMessageThread(Common.CLIENT_register, getAuthServerIP(), Common.AUTH_SERVER_PORT);

     blah.start(); 
      blah.join();           
}catch(InterruptedException ie){}              

-----------------------------------------------------------------------------------------------

 

The code segment in the UDP thread:

-----------------------------------------------------------------------------------------------

try
{                                     
     Datagram inDatagram = _receiveConnection.newDatagram(input, input.length);
      _receiveConnection.receive(inDatagram);  
                                
      // some cases only require the socket to receive one message, so close it after single use
      if(closeAfterReceive)
      {_receiveConnection.close(); }
                                                                                                                                
       return inDatagram.getData();
}
catch(IOException ioe) {System.out.println("Error: Receive packet failed! " + ioe);     return null;}

-----------------------------------------------------------------------------------------------

 

THIS IS VERY IMPORTANT TO MY PhD RESEARCH!!  PLEASE HELP!!!!

Please use plain text.
New Contributor
davidAU
Posts: 6
Registered: ‎03-04-2010
My Device: BlackBerry 9530 Development Simulator

Re: UDPDatagramConnection locks up on receive()

I was using the BlackBerry JDK 4.7.0.  This issue has been resolved in JDK 6.0.

Please use plain text.