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 vellino]

Hi Iain,

First of all, I want to say that I think your book is very timely
and I share your views about IM being an infrastructure to a lot
of chatbot / info-delivery applications. Thanks a lot for writing it.

I have a question about the code, which perhaps relates to the
previous qustion.

In chapter 8 (p.239) you talk about some test-code for subscribing to someone's
rosters and confirming subscription, adding a user to their roster etc.

Instead of using two threads (Hieu and Iain) and the IMJ server, I'm using
one thread (Hieu), one commercial IM client (Iain) and the jabberd
reference implementation server.

What I don't understand is that when I submit a request from the IM client
to add (Iain), the Hieu thread never seems to get the "presence" (note
the typo in the text on P.240) message requesting a subscription.

Any idea what's going on?

Cheers - Andre
import-bot (20211) [Avatar] Offline
#2
Re: Presence / Roster updates
[Originally posted by vellino]

.... a followup....

I did a little experiment, inspired by the suggestions you make early in
the book to telnet and send the XML by hand....

User A has the telnet session, User B is on a client, both are talking to
server S

A logs in... fine
B adds A to his roster
Nothing happens on A's telnet session
A queries his roster with:

<iq type="get" id="3CFF08AB">
<query xmlns="jabber:iq:roster"/>
</iq>

and gets a response:

<iq type='result' id='3CFF08AB' from='A@server/resource'>
<query xmlns='jabber:iq:roster'>
[list of items in roster]
</query></iq>
<presence type='subscribe' from 'B@server/resource'>
<status>Normal Subscription Request</status>
</presence>

What's that presence message doing there? That's a bug in jabberd, right? (I
shouldn't have to do anything to the server like a roster query to get a
presence message for a subscription request, should I?)

Mind you, I have a couple of jabberd transports plugged into the server
as well, could that be a problem?

Best - Andre
import-bot (20211) [Avatar] Offline
#3
Re: Presence / Roster updates
[Originally posted by iainshigeoka]

> First of all, I want to say that I think your book is very timely
> and I share your views about IM being an infrastructure to a lot
> of chatbot / info-delivery applications. Thanks a lot for writing it.

Hi,

Thanks for the kind words. I hope the book has proved useful.

> I have a question about the code, which perhaps relates to the
> previous qustion.
>
> In chapter 8 (p.239) you talk about some test-code for subscribing to
someone's
> rosters and confirming subscription, adding a user to their roster etc.
>
> Instead of using two threads (Hieu and Iain) and the IMJ server, I'm using
> one thread (Hieu), one commercial IM client (Iain) and the jabberd
> reference implementation server.
>
> What I don't understand is that when I submit a request from the IM client
> to add (Iain), the Hieu thread never seems to get the "presence" (note
> the typo in the text on P.240) message requesting a subscription.
>
> Any idea what's going on?

Is the IMJ client receiving any XML from jabberd regarding the subscription
request? The logging code should spit out any incoming XML while parsing.

Since you're using jabberd and not the book server, the roster issues in the
previous thread shouldn't be an issue. The book client is pretty simple and
should report anything it gets even if it was something unexpected.

If you don't mind, post as much debug information as you can to the forum. I
may be able to help pinpoint the problem. If the commercial client has a
debug output capability or if you have access to jabberd's logs it would be
even better.

-iain
import-bot (20211) [Avatar] Offline
#4
Re: Presence / Roster updates
[Originally posted by vellino]

> Thanks for the kind words. I hope the book has proved useful

Yes it has. I've learned quite a lot in the past few weeks or so.

>
> Is the IMJ client receiving any XML from jabberd regarding the subscription
> request? The logging code should spit out any incoming XML while parsing.

OK.... here goes...

I've modified your code a bit so that instead of having two client-threads
talking ot each other, I only have one IMJ client thread that talks to another
client application (JIM).

So first I launch the IMJ client and here's the log....

com.metamech.wocky.RosterClient
Initializing authenticator... initialized. Starting client...
Initializing Test Thread...
Initializing Jabber Model...
Authenticated Fred
22:15:44:527 [XS] URI: http://etherx.jabber.org/streams lName: stream qName:
stream:stream
22:15:44:537 [PQ] <stream:stream from='myjabberd.server.org' id='3CFF540A'/>
22:15:44:537 [XC]
22:15:44:537 [XS] URI: jabber:client lName: iq qName: iq
22:15:44:537 [XE] finished with iq
22:15:44:537 [PQ] <iq type='result' id='plain_auth_0'/>
Sending Presence for Fred to the server, waiting for subscribe message

[changed server names to protect the innocent]

----

for which the relevant code fragment is ....

public class fredTestThread extends TestThread {

public void run(){
try {
model.connect();
model.authenticate();
System.out.println(" Authenticated Fred");
do {
notifyHandlers(packetQueue.pull());
} while (model.getSessionStatus() != Session.AUTHENTICATED);
model.sendPresence(null,null,null,null,null);
System.out.println(" Sending Presence for Fred to the server, waiting
for subscribe message");
waitFor("presence","subscribe");

....

-----

Now, from the JIM client, which is logged into the same jabberd server, I now
"add contact" for "fred" (from the GUI). The JIM client tells me that "fred
(pending)", which presumably means he's sent a subscribe message to the
server.

But the IMJ client is still waiting for the presence message (it never gets
it) (which is confirmed by looking at incomming messages from Telnet )

Now, if you add to the code fragment above a call to:

model.sendRosterGet();

just before the "waitFor" method, then, when the JIM client adds "fred" to his
roster, the message is received properly.

My guess is that this is a server bug. Introduced, possibly, by the MSN
transports that I've added. I'll fiddle with that and let you know.

Cheers - Andre
import-bot (20211) [Avatar] Offline
#5
Re: Presence / Roster updates
[Originally posted by vellino]

.... continued....

So I did some fiddling with the server and the client, and I'm at a loss!

If I take two GUI clients (JIM for User A and WinJab for User B for example),
and I log them both into the jabberd server, then, when I "add B" to the
user-list in A's client I get an immediate response B's client (which is what
you'd expect).

Hence, I conclude that the server is behaving properly.

Perhaps I'm just not understanding how to whom and when presence messages get
sent? For example, what happens when a jabber client application crashes? (How
does the server and other clients know that the user is no longer present?)

Regards - Andre
import-bot (20211) [Avatar] Offline
#6
Re: Presence / Roster updates
[Originally posted by iainshigeoka]

Hi Andre,

I think you've uncovered an implementation specific behavior of jabberd. It
appears that you don't get roster updates (including subscription requests)
until you ask for the roster first. The GUI clients do this as part of their
login process (authentication, presence -> available, and roster get).

As you've uncovered, sending a roster get triggers the subscription request
delivery. In my opinion, this is a jabberd server bug. However, since it is
established practice and the behavior of the reference server, practically
speaking, you're best off making the client accomodate jabberd's behavior.

In some ways it makes sense for the protocol to behave this way since a
desktop client would want to display the new roster entry (subscription)
immediately after accepting the subscription but couldn't until it did a
roster get any way. Notice how the jabberd implementation is heavily targeted
towards simplifying work for desktop IM clients.

Remember that the client that came with the book was designed to test the
book's jabber server and not as a general purpose jabber client. There are
probably other jabberd gotcha's that you'll have to adjust for when building a
general purpose jabber client.

In addition, the jabber standards process is picking up steam and we're
starting to see many new client protocols emerging that you'll want to
support. For example, a generic jabber emoticon standard is being discussed
so that you can display smileys and other graphics in IM messages.

What are your thoughts Andre?

-iain
import-bot (20211) [Avatar] Offline
#7
Re: Presence / Roster updates
[Originally posted by vellino]

Hi Iain,

I think your interpretation is correct, but I would definitely say that this
is a bug in jabberd - presence messages should always be sent without being
polled-for by the client.

Thanks for your help with this. I'll be in touch again!

- Andre
import-bot (20211) [Avatar] Offline
#8
Re: Presence / Roster updates
[Originally posted by iainshigeoka]

> I think your interpretation is correct, but I would definitely say that this
> is a bug in jabberd - presence messages should always be sent without
being
> polled-for by the client.

After thinking about this a while I agree with you entirely. this is a bug.

If you have the time, you should file a bug on this with them
(www.jabber.org). They would appreciate the info and may be able to
provide more insight into why the server behaves this way (whether its just
an implementation problem or if there is a reason we haven't thought of
behind the behavior).

Best wishes

-iain