Welcome to the Official BlackBerry® Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
New Developer
uncleop
Posts: 17
Registered: 11-17-2009

Simulator and sockets: where does RIM end and native O/S begin?

[ Edited ]

Problem setup: I am trying to diagnose a problem I see where InputStream's read() will hang on a TCP socket connection under the simulator. It works fine for many thousands of bytes, but eventually it just doesn't get its data. Wireshark shows that the data is indeed being transmitted and received by the host OS (Windows XP Pro, SP3). The data drop/hang seems to be random; it typically occurs after about 8-9MB of data has been sent on the OutputStream side of the socket.

 

This problem may be the same unresolved problem reported in: http://supportforums.blackberry.com/t5/Java-Development/TCP-connections-suck-any-of-them/td-p/350059

 

If I try different versions of the JDE (so far I've worked with 4.6, 4.6.1, and 4.7) I still see the problem. I tried running with a 5.0 simulator but the 4.7 JDE.

 

The question: Does the simulator drive the I/O, or is it the JDE, or is it all left to the version of Java running on the system? I.e., if I use a different simulator, how much of the low-level code is just what would run on the phone, and how much gets handed off to the host O/S of the simulator?

 

I haven't tried 5.0 under Eclipse yet.

 

The Java I'm using reports as:

java version "1.6.0_17"

Java(TM) SE Runtime Environment (build 1.6.0_17-b04)

Java HotSpot(TM) Client VM (build 14.3-b01, mixed mode, sharing)

Thanks for any tips,

-Del

 

[edited to clean up formatting]

Please use plain text.
Developer
Posts: 1,474
Registered: 04-14-2009

Re: Simulator and sockets: where does RIM end and native O/S begin?

1. Does the issue occur on an actual BlackBerry?

 

2. Does the issue occur when you connect to a known good TCP server (e.g., NetCat) or HTTP server (e.g., Apache, Tomcat)?

 

3. Have you analyzed TCP-level traffic to see which side is to blame (e.g., it could be that the server is resending the same window, which the client has already received, or it could be that the client isn't acking the window...)?

 

4. If you can reproduce the issue reliably with a known good server and you know that it is the BlackBerry that is to blame, you should submit the issue into RIM's Developer Issue Tracker so that RIM can fix the issue and/or suggest a workaround.

Please use plain text.
New Developer
uncleop
Posts: 17
Registered: 11-17-2009

Re: Simulator and sockets: where does RIM end and native O/S begin?

[ Edited ]

Sorry for the poor/non-formatting in the post. I don't see the "edit" button to let me clean it up.

 

[edit: looks like the forums now support IE better than Firefox.  sad.]

Please use plain text.
New Developer
uncleop
Posts: 17
Registered: 11-17-2009

Re: Simulator and sockets: where does RIM end and native O/S begin?

1. I have reports that it occurs on a phone.  It only happens during long/large data transfers, and is not predictable.

 

2. The server is known to be at least pretty good (samba running on Linux and hoards of native Windows smb servers).

 

3. wireshark data looks completely clean - last packet received as a response to a phone/simulator request is completely as expected.

 

4. I am in fact trying to confirm that it is RIM/BlackBerry to blame.  But the earlier post I mention seems to suggest it could be more of a Windows/Simulator API issue.  And it is not something that is reliably reproduced. 

 

Thanks,

-Del

Please use plain text.
Developer
Posts: 1,474
Registered: 04-14-2009

Re: Simulator and sockets: where does RIM end and native O/S begin?

In point 3 above, are you saying that according to TCP packet dump all of the data was successfully transfered and acked over the TCP connection and the connection was gracefully closed? If so, this would suggest that the TCP stack on the BlackBerry did its job but the upper layer wasn't notified or didn't read the application-level data correctly. In this case the next question is whether your connection reading code is correct.

Please use plain text.
New Developer
uncleop
Posts: 17
Registered: 11-17-2009

Re: Simulator and sockets: where does RIM end and native O/S begin?

No, the model for data transfer is:

- send "packet" from phone to device via WiFi (in one thread)

- wait for response/ack (at protocol, not TCP) layer (in a different thread)

- repeat until done

 

The socket remains open during the entire transmission of data.  Data transmission is all TCP from the application's point of view.

 

Wireshark says that Windoze got the response data from the device and that it was well-formed.  Part of my question concerns the boundary - in the simulator environment - between RIM-supplied networking code and host-O/S-supplied code.

 

The reading thread is definitely hanging on the equivalent of:

myReadIt (InputStream is, int n, byte[] buf) {

  in.read(buf, 0, n);  // hang is on the read

}

I've left out the fact that the in.read() is in a loop and try/catch (standard practice) for clarity.

 

What happens is I detect a timeout over in the writer thread because the protocol requires the response from the reader thread.  When the writer thread forces an explicity close() on the socket, the hung read throws an exception, which is caught in myReadIt().

 

I've only been doing networking stuff for 25 years, though, so I could be missing something.  (My BlackBerry time, however, is far shorter - just about a year now...)

Please use plain text.
Developer
Posts: 1,474
Registered: 04-14-2009

Re: Simulator and sockets: where does RIM end and native O/S begin?

[ Edited ]

Are you checking how many bytes were actually returned by InputStream.read? Sorry for asking this, but quite a lot of networking issues reported on this forum boil down to not reading the javadocs of InputStream.

 

If you are doing everything correctly, and if you can easily reproduce the issue, do submit it to RIM's Developer Issue Tracker.

Please use plain text.
New Developer
uncleop
Posts: 17
Registered: 11-17-2009

Re: Simulator and sockets: where does RIM end and native O/S begin?

Yes, indeed I am checking the number of bytes returned. There is no question that the read is blocked. Unfortunately, it's not "easy to reproduce". I'll see what I can cobble together. May take some time.
Please use plain text.
New Developer
uncleop
Posts: 17
Registered: 11-17-2009

Re: Simulator and sockets: where does RIM end and native O/S begin?

Trying my application on another system - Windows XP Pro SP2 - and it works fine. Best guess is that XP Pro SP3 introduced a TCP bug or there's some other software on that system that I forgot I installed. Annoying, Windows is.
Please use plain text.