The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

import-bot (20211) [Avatar] Offline
#1
[Originally posted by munavar]

I'm developing J2ME based Jabber client. I'm presently facing following problem.
1.)The client thread blocks when data is not available in read, then we cannot
also write to that socket.

2.)To solve this I read only after sending something. Is it possible to send
some empty tags to the server regularly so that in return I will be able to
read messages if any pending with the server, so that my read doesn't block.

3.)Currently I stop reading when I get an end tag to the corresponding opening
tag to prevent blocking.

As I'm using J2ME the 'available()' and 'ready()' methods always returns
incorrectly. Please help me.
import-bot (20211) [Avatar] Offline
#2
Re: Regarding heart beat
[Originally posted by iain.shigeoka]

> I'm developing J2ME based Jabber client. I'm presently facing following
problem.
> 1.)The client thread blocks when data is not available in read, then we cannot
> also write to that socket.

You have to use a thread to read from the socket while another thread handles
the other application tasks (including writing to the socket). Doesn't J2ME
allow multiple threads?

> 2.)To solve this I read only after sending something. Is it possible to send
> some empty tags to the server regularly so that in return I will be able to
> read messages if any pending with the server, so that my read doesn't block.

Yes, but this won't solve your problem. If there is another message waiting,
then your read will only read the reply to the packet you sent and not the
pending message. You'll always have to try to read again to see if there were
in fact two packets (or more than two packets).

-iain