OutputStream on J2ME

L

Lureon

Hi

I am attempting to write a serial port listener for J2ME (receive
message and echo it back). I have managed to get it working except for
1 strange problem. The fist time it sends a reply, there are some
garbage bytes in the stream.

Does anyone have any idea how to remove them. Flushing is no use as the
device connected to the port will receive the garbage which I don't
want.

J2ME OutputStream doesn't seem to have a .clear() method.

Any help would be appreciated.

Thanks
Duane
 
J

JScoobyCed

Lureon said:
Hi

I am attempting to write a serial port listener for J2ME (receive
message and echo it back). I have managed to get it working except for
1 strange problem. The fist time it sends a reply, there are some
garbage bytes in the stream.

Does anyone have any idea how to remove them. Flushing is no use as the
device connected to the port will receive the garbage which I don't
want.


Switch off the phone and restart it, then launch your application. The
very first time, does it have the garbage bytes?
If not, but all following times have it, then it means that when you
close the stream you leave some unsent bytes. The phone seems to keep
them until next time you open the port and send something. In this case,
make sure you flush() the outputstream at the end, before closing the
connection.

Hope it'll help.

JSC
 
L

Lureon

Hi Thanks for your reply

It's not a phone, it's a Wireless Module, but almost the same :)

It only does this the 1st time I open the connection (after a restart).
I have tried to flush() just after opening but it doesn't work.

If I open the connector:
Open the outputstream and inputstream
Then I write something and then flush.
The 'something' and the garbage are only sent when I have read the
1st message and replied ([garbage][something][reply])
After that, it works perfectly.

It seems like the flush doesn't work.

Does anyone know of any way to empty the buffer without sending the
data?

Thanks
Duane
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,076
Latest member
OrderKetoBeez

Latest Threads

Top