10-23-2008 06:37 AM
The problem has been further analyzed and the cause has been clearly identified.
The nature of the problem can be summarized as follows:
InputStreamReader is totally broken when used with a SocketComnection. Although setting READ_TIMEOUT does appear to produce a partially working implementation it is still broken. When a timeout does occur an IOException results with the message "TCP read timed out" and there is absolutely no way to resume read() on the stream. But without setting READ_TIMEOUT incoming data totally stops after delivering a couple of hundred bytes. Tested on 8708g and 9000.
By contrast, DataInputStream works perfectly.
On other phones using different Java VM implementations, both DataInputStream and InputStreamReader work perfectly on SocketConnection's. I have tested at least 12 different handsets from different manufacturers (Sony, Morotola, LG, Nokia, Samsung, HTC, etc). Only on RIM's BlackBerry platform is InputStreamReader totally broken. This includes sdk versions 4.2.1 through 4.5.0 but it is most likely a problem with device system software/java vm.
I don't quite understand how Sun could allow BlackBerry to implement such a broken InputStreamReader because it only helps give Sun's product a bad name. And I am even more amazed that this problem has existed for so long.
I am not impressed with the quality of advice on this forum either.
03-27-2009 03:31 PM
Thank you bb9 for pointing out that the InputStream does not work with socket connection but DataInputStream does.
I replaced the InputStream with DataInputStream in my source code and it works! I have been trying to figure out this strange behaviour that I am encountering for a long time -- When I loaded the same app cods to the 9000 simulator (running on v22.214.171.124 (Platform)) , I get a connection closed exception, however it runs perfectly fine using the same cods on the real 9000 device(running on v126.96.36.199(Platform 188.8.131.52)).