enhering has asked for the wisdom of the Perl Monks concerning the following question:

Hi. On the following code I need to send a
message to a jabber client and wait for its
answer. Is there a way of doing this without
using a callback?
$self->{conn} = new Net::Jabber::Client(); $self->{conn}->SetCallBacks(message=>\&InMessage, presence=>\&InPresence, iq=>\&InIQ); my $status = $self->{conn}->Connect( hostname=>$self->{Host}, port=>$self->{Port}, ); ... sub gpib_read { my $self = shift; print "Reading from gpib UD=$self->{ud}.\n" if ($debug); my $message = "GPIB|read|$self->{ud}"; $self->{conn}->MessageSend(to=>'gpibserver@192.168.0.2', subject=>"", body=>$message, thread=>"", priority=>10); #Blocks until answer comes $self->{conn}->Process(); # Answer comes through callback InMessage. Is there a way # of expecting the answer here? }

Best regards,

Eduardo.

Replies are listed 'Best First'.
Re: Net::Jabber: Receiving answers without callbacks
by zengargoyle (Deacon) on Aug 31, 2006 at 19:51 UTC
    not sure about using messages... can you make your query/reponse into 'iq' packets? maybe this will work with messages also, i just haven't tried. this is from a bot that gets a list of users in chatrooms.
    while (1) { $count_rooms = 0; %count_users = (); open $html, '>:utf8', 'chatters.html'; print $html qq{<h2>Currently in Chatrooms</h2>\n<ul>\n}; my $Rep; $Rep = $Connection->SendAndReceiveWithID( new_get_iq($ME, $CS, $NS_D_ITEMS), 10); rep_dump( $Rep ); print $html qq{</ul>\n}; close $html; print "Count: $count_rooms rooms, ",scalar(keys %count_users), +" users\n" ; sleep(60); }
    the SendAndReceiveWithID function will send the IQ Query and wait for the IQ Response before continuing.
Re: Net::Jabber: Receiving answers without callbacks
by qbxk (Friar) on Aug 31, 2006 at 16:19 UTC
    Why don't you want to use callbacks? That's the Net::Jabber interface. I guess you could use a different interface though, a quick glance at Jabber::Lite looks like it doesn't use callbacks...

    It's not what you look like, when you're doin' what you’re doin'.
    It's what you’re doin' when you’re doin' what you look like you’re doin'!
         - Charles Wright & the Watts 103rd Street Rhythm Band, Express yourself
Re: Net::Jabber: Receiving answers without callbacks
by nicholasrperez (Monk) on Sep 01, 2006 at 20:05 UTC
    Have you taken a look at POE::Component::Jabber? There might be a learning curve if you aren't familiar with POE, but much more worth it. Also, you have a lot more control over the client and the data going into and out of P::C::J.
A reply falls below the community's threshold of quality. You may see it by logging in.