BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 02-19-2009, 12:49 PM   #1 (permalink)
New Member
 
Join Date: Feb 2009
Model: NONE
PIN: N/A
Carrier: NONE
Posts: 4
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default IOException while calling UDPDatagramConnection.send - can't figure that one out

Please Login to Remove!

OK, I tried this from every possible angle, I am clearly missing something. You help would be the most welcome. I am using the BlackBerry Java Development Environment Version 4.6.0.12 on Windows XP and my developer environment is functional with all the samples running fine (a good sign that I have java well installed and all).

1) THE OBJECTIVE:

Sending a UDP packet from a BlackBerry client (right now the 9000 BB Simulator) to a functional C# server. I already have a functional C# client that communicates successfully with the C# server, so I know that it is indeed functional.

2) THE CODE (partial):

public class UDPRepeaterCommunicationLayerClass extends CBaseMessageWrappingClass implements CommunicationInterface, Runnable
{
public static final String m_protocol = "udp";
private final boolean m_debug = true;
private int kDefaultMaxPacketSize = 3500;
private int kMaxPacketSize = kDefaultMaxPacketSize;
private int kMaxRetries = 5;
protected String m_address;
private UDPDatagramConnection m_socket = null;
private byte[] m_buffer = null;
private String m_remoteEndPoint = null;
private Hashtable m_pendingACK = new Hashtable();
private int m_ACKTimeoutCount = 0;
private UnsolicitatedDisconnectNoticeable m_unsolicitedDisconnectToCall = null;
private Vector m_queuedMessages = new Vector();
private Thread m_UDPreceiveThread = null;

UDPRepeaterCommunicationLayerClass(String dAddress, UnsolicitatedDisconnectNoticeable dDelegate) throws IOException
{
m_unsolicitedDisconnectToCall = dDelegate;
if (m_debug) System.out.println("Verifying if coverage is sufficient.");
if (!CoverageInfo.isOutOfCoverage())
{
if (m_debug) System.out.println("Coverage is sufficient.");
if (dAddress == null)
{
// dAddress = UDPRepeaterCommunicationLayerClass.m_protocol + "://localhost:7180;7181/";
dAddress = UDPRepeaterCommunicationLayerClass.m_protocol + "://localhost:7180";
}
if (m_debug) System.out.println("Opening connector " + dAddress);
m_socket = (UDPDatagramConnection)Connector.open(dAddress);
m_address = m_socket.getLocalAddress() + ":" + String.valueOf(m_socket.getLocalPort());
if (m_debug) System.out.println("Connector address obtained: " + m_address);
SetMaxPacketSize(kDefaultMaxPacketSize);
m_buffer = new byte[kMaxPacketSize + 200];
}
else
{
if (m_debug) System.out.println("Coverage is not sufficient.");
}
}

...

public synchronized void SendData(String address, int dMessageType, byte[] dDataBytes) throws IllegalArgumentException
{
try
{
AssignNewMessageId();
if ((kMaxPacketSize + 200) > m_socket.getMaximumLength())
{
kMaxPacketSize = (m_socket.getMaximumLength() - 200);
}
if (m_debug) System.out.println("Calling WrapMessage into SendData");
Vector packets = WrapMessage(m_address, dMessageType, dDataBytes, kMaxPacketSize);
if (m_debug) System.out.println("WrapMessage constructed " + String.valueOf(packets.size()) + " packet(s)");
for (int curPacket = 1; curPacket <= packets.size(); curPacket++)
{
m_bytesUsed += (long)((byte[])(packets.elementAt(curPacket-1))).length;
if (m_debug) System.out.println("Packet #" + String.valueOf(curPacket) + " is " + String.valueOf(((byte[])(packets.elementAt(curPacket-1))).length) + " bytes.");
Datagram dNewDatagram = m_socket.newDatagram(((byte[])(packets.elementAt(curPacket-1))).length);
// if (m_debug) System.out.println("dNewDatagram.setAddress to " + address);
// dNewDatagram.setAddress(address);
if (m_debug) System.out.println("calling dNewDatagram.setData");
dNewDatagram.setData(((byte[])packets.elementAt(curPacket-1)), 0, ((byte[])(packets.elementAt(curPacket-1))).length);
if (m_debug) System.out.println("calling send");

// EXCEPTION THROWN HERE (in the send call)...

m_socket.send(dNewDatagram);
if (m_debug) System.out.println("send call succeeded");
CResendDataContext dContext = new CResendDataContext();
dContext.m_retriesCount = 0;
dContext.m_maxRetries = kMaxRetries;
dContext.m_endPoint = address;
dContext.m_data = (byte[])(packets.elementAt(curPacket-1));
dContext.m_packetIdentifier = m_messageId + "." + String.valueOf(curPacket);
if (dContext.m_maxRetries > 0)
{
dContext.m_timer = new Timer();
dContext.m_timer.schedule(dContext, 1000, 1000);
m_pendingACK.put(dContext.m_packetIdentifier, dContext);
}
}
}
catch (IOException e)
{
if (m_debug)
{
System.out.println(e.toString());
System.out.println(e.getMessage());
e.printStackTrace();
}
Dispose();
if (m_unsolicitedDisconnectToCall != null)
{
m_unsolicitedDisconnectToCall.UnsolicitatedDisconn ect();
m_unsolicitedDisconnectToCall = null;
}
}
}
}

... and the caller:

// FINE: We create a client connection

if (m_debug) System.out.println("Creating UDPRepeaterCommunicationLayerClass");
m_commLayer = new UDPRepeaterCommunicationLayerClass(null, this);
if (m_debug) System.out.println("UDPRepeaterCommunicationLayerC lass created");
m_commLayer.StartReceiveThread(m_commLayer, this);
if (m_debug) System.out.println("UDPRepeaterCommunicationLayerC lass thread started");
CValuePairConfig dConfigs = new CValuePairConfig();
dConfigs.SetValuePair("touchscreen", "yes");
dConfigs.SetValuePair("physicalkeyboard", "no");
dConfigs.SetValuePair("screenwidth", "480");
dConfigs.SetValuePair("screenheight", "320");
dConfigs.SetValuePair("commlayer", "EDGE");
dConfigs.SetValuePair("sendhidefscreen", "no");
dConfigs.SetValuePair("periodicalupdate", "0");
dConfigs.SetValuePair("maxpacketsize", String.valueOf(m_commLayer.GetMaxPacketSize()));

// FINE: We prepare the call to the server on the same IP address as the client for now, but at port 7180

m_serverAddr = UDPRepeaterCommunicationLayerClass.m_protocol + "://" + m_commLayer.GetLocalIPAddress() + ":7180";
// m_serverAddr = "datagram://" + m_commLayer.GetLocalIPAddress() + ":7180";
if (m_debug) System.out.println("m_serverAddr is " + m_serverAddr);
String dContent = dConfigs.GetContent();
if (m_debug) System.out.println("dContent is " + dContent);

// Everything works fine until here... IOException thrown following that call...

m_commLayer.SendData(m_serverAddr, CommunicationInterface.eMsgTypeClientSysInfoXchang e, dContent);

// We never get here (exception thrown before).

if (m_debug) System.out.println("eMsgTypeClientSysInfoXchange sent");

3) THE RESULTS:

Regardless on my approach (and I have tried it from so many angles), I always get an IOException from the send method (in Transport.NativeSend if referring to the stack trace following). No packet gets to the server whatsoever.

Creating UDPRepeaterCommunicationLayerClass
Verifying if coverage is sufficient.
Coverage is sufficient.
Opening connector udp://localhost:7180
Connector address obtained: 192.168.1.102:58955
UDPRepeaterCommunicationLayerClass created
UDPRepeaterCommunicationLayerClass thread started
m_serverAddr is udp://192.168.1.102:7180
dContent is physicalkeyboard=no
commlayer=EDGE
touchscreen=yes
sendhidefscreen=no
maxpacketsize=1492
periodicalupdate=0
screenwidth=480
screenheight=320
Calling WrapMessage into SendData
WrapMessage constructed 1 packet(s)
Packet #1 is 182 bytes.
calling dNewDatagram.setData
calling send
java.io.IOException
null
IOException
No detail message
net_rim_cldc-13
Transport
nativePreSend
0x991D
net_rim_cldc-13
NativeTransport
send
0x4A53
net_rim_cldc-5
DatagramTransportBase
superSend
0x2273
net_rim_cldc-4
DatagramConnectionBase
send
0x2F7A
PhoneInputMidlet
UDPRepeaterCommunicationLayerClass
SendData
0x1399
PhoneInputMidlet
UDPRepeaterCommunicationLayerClass
SendData
0x125E
PhoneInputMidlet
RemoteControlCanvas
<init>
0x1095
PhoneInputMidlet
LoginForm
remoteControl
0x96B
PhoneInputMidlet
LoginForm
validateUser
0x946
PhoneInputMidlet
LoginForm
commandAction
0xA03
net_rim_cldc-16
Lcdui
<private>
0x7BB3
net_rim_cldc-16
Lcdui
runCallback
0x7E5A
net_rim_cldc-3
MIDletMain
updateScreen
0x4E9C
net_rim_cldc-9
UiEngineImpl
processMessage
0xA320
net_rim_cldc-6
Application
processNextMessage
0xF06
net_rim_cldc-6
Application
enterEventDispatcher
0x5C6
net_rim_cldc-3
MIDletMain
main
0x5173

4) WHAT I HAVE TRIED SO FAR:

- I changed the 'udp' protocol to 'datagram' and the results were the same (both approaches succeeded up to the send method where an IOEXception was thrown).
- I edited the command-line available under the Simulator tab of the JDE preferences. It now contains the following (added /data-port entries):

C:\Program Files\Research In Motion\BlackBerry JDE 4.6.0\bin\..\simulator\fledge.exe /app=Jvm.dll /session=9000 /app-param=JvmAlxConfigFile:9000.xml /data-port=0x4d44 /data-port=0x4d4e /data-port=0x1C0D /data-port=0x0D1C /data-port=0x1C0C /data-port=0x0C1C /pin=0x2100000A /ignore-data-port-conflicts=true /app-param=DisableRegistration /handheld=9000

- My network tab (under Simulator in the JDE preferences) is pretty much empty but I have tried a configuration of things there also.
- I have tried to assign an outgoing port by changing the open parameter to the following (as commented in the code before), with both the udp and datagram protocols:
// dAddress = UDPRepeaterCommunicationLayerClass.m_protocol + "://localhost:7180;7181/";

Any help would be the most welcome. Thanks in advance for reading through this detailed post.

Philippe Roy
Canada
Offline  
Old 02-19-2009, 03:12 PM   #2 (permalink)
Thumbs Must Hurt
 
Join Date: Apr 2005
Model: 950
Carrier: T-Mobile
Posts: 185
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Have you tried this on a real device?
Offline  
Old 02-19-2009, 04:19 PM   #3 (permalink)
New Member
 
Join Date: Feb 2009
Model: NONE
PIN: N/A
Carrier: NONE
Posts: 4
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by jonberry View Post
Have you tried this on a real device?
No, I have not. I want to get this to work on the Simulator prior to investing in getting a real BlackBerry (still a significant amount of money involved).

I hope someone on this forum can guide me towards a solution of this problem...

Thanks
Offline  
Old 02-19-2009, 05:45 PM   #4 (permalink)
New Member
 
Join Date: Feb 2009
Model: NONE
PIN: N/A
Carrier: NONE
Posts: 4
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have also looked into application signing. It does not appear that the APIs that I am using require signing, but could someone confirm that?

Has anyone succeeded producing some code sending and receiving UDP packets within the Simulator? Anyone could share sample code? Although I have found some online, it ain't enough to build a functional class from it.

Thank you.
Offline  
Old 02-19-2009, 08:00 PM   #5 (permalink)
New Member
 
Join Date: Feb 2009
Model: NONE
PIN: N/A
Carrier: NONE
Posts: 4
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I downloaded a freeware progrma that scans for opened ports on the local computer (CurrPorts), and it turns out that even if Connector.open succeeds, the UDP port (also tried with the datagram protocol and had the same result) doesn't show up in the list.

It is almost as is the port was not binded (the output gives me a port number but that port number does't show up as busy while it is open).

Does the Simulator force me to play within a sandbox that I am not aware of? This is all so unexpected.

Thank you
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.