views:

725

answers:

1

On sending data over bluetooth from PC to my mobile(N73), the Input Stream seems to hang up. InputStream is derived from StreamConnection.

PC software is built in VB.net. Mobile in Java ME.

Does the InputStream have an internal buffer that needs to be emptied while reading large chunks of data? Data is being received in chunks of 10Kb to 15Kb range, and the reading stops after receiving the 3rd chunk. Strangely I am not receiving any exceptions.

I browsed through the InputStream class API documentation and couldn't find any InputStream clear or empty method. There is only a reset() method, I don't know what its used for?

+2  A: 

InputStream.reset() is a method you would call sometime after having used Inpustream.mark() to force the InputStream to create an internal buffer that would allow you to read the same data multiple times, assuming the InputStream supports it by returning true when calling InputStream.markSupported().

As far as the data transmission issue, we're talking about a handset running Series60 3rd edition on top of Symbian OS 9.1. Given how extensive the Symbian testing of JSR-82 was, an implementation bug as simple as a 40k limit on the InputStream seems unlikely.

Does the handset behavior change if the server sends smaller chunks at a much lower bitrate?
Does the handset process received data before reading some more?
What else is the MIDlet doing? Is everything else working as expected even after the bluetooth InputStream blocks?

I do remember a fairly important bug in the JSR-82 implementation that might have been fixed only after the initial N73 firmwares were created: do not use bluetooth at all in any event dispatching thread (not from any method like MIDlet.startApp(), Canvas.keyPressed(), CommandListener.commandAction(), PlayerListener.playerUpdate()...).

You are better off only using bluetooth from inside a Thread.run() method you wrote yourself.

QuickRecipesOnSymbianOS
I have not tried sending smaller chunks at lower bitrate?How do I control the bluetooth bitrate of the handset, I don't think I have enabled that setting, and whatever it is, its running on default right now? This seem to be an important issue.The handset is just storing all the chunks of data in seperate slots of a Vector, each slot is a byte array.The Midlet at this point is just reading from input stream (1st thread), writing to output stream(2nd thread) and painting a canvas (3rd thread). And the painting is more of a log at the moment for me to debugt the handset.
Kevin Boyd
I found an important PDF on the web titled "J2ME Bluetooth Programming" by Andre Klingsheim. In the category of Bluetooth Pitfalls he states:"Care must also be taken concerning the amount of data sent at once. It seems one ofthe buffers in use in the 6600 and P900 smartphones is 512 bytes. When trying totransfer more than 512 bytes at once, the receiver gets 512 bytes and then theconnection will freeze. Sending 512 bytes, flushing, sending 1 byte back, and flushingworks fine. The connection is then kept alive. "
Kevin Boyd
Is it a known issue as reported in "Using Bluetooth serial port in MIDlets" on the Nokia wikiKIJ000109OverviewReading incoming stream does not work properly in certain Nokia S60 and Series 80 devices.Reported againstS60 2nd Edition: Nokia 6600 v.4.09.1S60 2nd Edition, Feature Pack 1: Nokia 6620, Nokia 6260, Nokia 6670, Nokia 7610Series 80 2nd Edition: Nokia 9300, Nokia 9500This document seems to be dated to 2004.They should have surely solved the bug now.
Kevin Boyd
I certainly would hope that buffer issue has been fixed in recent phones but remember that, even though your N73 is an order of magnitude better than all the handsets you quoted, it could still be over 3 years old.
QuickRecipesOnSymbianOS
Yeah I think it would be, the firmware version with the *#0000# code shows a date of 27-07-2007 so its at least 2 years on the run. Maybe I could try and update the firmware on the phone and see how it goes from there. Alternatively I would set up a On device debugging or send the STDOUT or STDERR streams from the handset to a PC terminal just to get a finer understanding whats going on beneath the scenes.
Kevin Boyd
Well, I still don't understand about the inputStream.reset() and mark() methods, and what they do, should I use it in my code, is it a possible solution to the problem, there's no harm in giving a try!
Kevin Boyd
you go mark();read();reset(); then read() the same data again. I don't think that would be of any use to solve a bluetooth-specific issue.
QuickRecipesOnSymbianOS
for stdout and stderr, see http://stackoverflow.com/questions/225489/how-to-get-the-text-of-an-exception-stack-trace-in-javame/226253#226253
QuickRecipesOnSymbianOS
Well thanks for the STDOUT and STDERR links, I've been trying to get it working but its not yet up on my N73. It gives wierd errors like ecmt manager cant start. Well I shall look what I can get at that link.
Kevin Boyd