Hi guys
I have a basic app which sends a number via a socket connection to a gateway, and should then read the response from the gateway. This application was written in J2ME and LWUIT, and works well on Symbian and similar handsets. I set out to port it for BlackBerry but I seem to have some basic networking troubles.
The J2ME code works 100% on the BlackBerry 9500 up until where it is supposed to receive. It just never gets any data in the inputstream (datainputstream to be more specific) and subsequently times out.
- Sending works 100% on the original code.
- I am testing all of this on the 9500 simulator with the MDS thing running before the emulator.
- I can also see that the gateway actually sends back a proper response
- I have tried to write a basic version of the application without using LWUIT, and using the BlackBerry JDE 4.7, as raw as possible, but nothing works. Still sending, but no receiving.
Code:
public boolean Connect()
{
try
{
System.out.println("Attempting to connect to " + theServer + ":" + thePort);
clientConnection = (SocketConnection)Connector.open("socket://" + theServer + ":" + thePort + ";deviceside=true");
//clientConnection.setSocketOption(SocketConnection.LINGER, 5);
inputStream = clientConnection.openInputStream();
outputStream = clientConnection.openOutputStream();
connected = true;
return true;
}
catch (InterruptedIOException ex)
{
System.out.println("Exception:" + ex.toString());
ex.printStackTrace();
System.out.println("Connection timeout/interupted!");
connected = false;
return false;
}
catch (IOException ex)
{
System.out.println("Exception:" + ex.toString());
ex.printStackTrace();
System.out.println("Connection failure!");
connected = false;
return false;
}
catch (SecurityException ex)
{
System.out.println("Exception:" + ex.toString());
ex.printStackTrace();
System.out.println("Connection failure!");
connected = false;
return false;
}
catch (Exception ex)
{
System.out.println("Exception:" + ex.toString());
ex.printStackTrace();
System.out.println("Connection failure!");
connected = false;
return false;
}
}
// and here is a sample of the receiving code
// check for timeout, and if bytes are available, else continue
while ((inputStream.available() <= 0) && (count <= timeoutsecs))
{
try
{
System.out.println("Zero bytes available bytes in inputStream: " + count);
System.out.println("-----------------------------------------------");
Thread.sleep(1000);
count++;
}
catch (InterruptedException ex)
{
ex.printStackTrace();
break;
}
}
// reason for using dataInputStream in J2ME is
// so I can make use of readInt(), readBoolean() etc
header = 255;//inputStream.readShort();
messageType = 7;//inputStream.readByte();
messageStatus = true;//inputStream.readBoolean();
//etc... ANY clues as to why this thing / emulator is not receiving would be very helpful.
Thanks
w