mehov / xmpphp

Automatically exported from code.google.com/p/xmpphp
0 stars 0 forks source link

Simple whitespace ping implementation #52

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

while playing with XMPPHP I've found that it doesn't implement any keepalive 
feature and I the 
persistent bot being developed here was being dropped from time to time by the 
XMPP server 
(openfire, defaulting to xmpp.client.idle = 6 mins).

It seems that there are two ways to fix this:

1) Send one whitespace ping at regular intervals as commented in 
http://xmpp.org/extensions/xep-0198.html
2) The preferred way, implement XMPP-Ping - 
http://xmpp.org/extensions/xep-0199.html

So, being lazy as I am, I've added a quick modification, implementing 
whitespace pings at regular 
intervals (70 secs). It seems that it makes long-running clients (like bots) to 
work really better.

Adding here the implemented modification in case it helps. Thanks for your cool 
library, ciao, 
Eloy (stronk7)

Original issue reported on code.google.com by stro...@stronk7.com on 24 Apr 2009 at 5:36

Attachments:

GoogleCodeExporter commented 9 years ago
The server I'm trying to connect to doesn't pay any attention to the whitespace 
ping, so I had to do a (half-assed) implementation of XMPP-Ping. This is not a 
full implementation, only enough to send a pong back to an incoming ping.

First I implemented swa...@gmail.com's xpath_parse.patch from 
https://code.google.com/p/xmpphp/issues/detail?id=44

Then in XMPP.php, around line 136, I added:
        $this->addXPathHandler('iq/{urn:xmpp:ping}ping', 'ping_handler');

Then, same file, among the handler functions (say line 375):
    /**
    * Ping handler
    * Gets all packets matching XPath "iq/{urn:xmpp:ping}ping'
    *
    * @param string $xml
    */
    protected function ping_handler($xml) {
        $payload['from'] = $xml->attrs['from']; //lh3
        $payload['to'] = $xml->attrs['to'];     //ltlbot
        $payload['id'] = $xml->attrs['id'];     //ltlbot
        $payload['type'] = $xml->attrs['type']; //get
        if ($xml->attrs['type'] == 'get') {
            $this->send("<iq from=\"{$xml->attrs['to']}\" to=\"{$xml->attrs['from']}\" id=\"{$xml->attrs['id']}\" type=\"result\" />");
        }
    }

Deborah

Original comment by deborah....@gmail.com on 17 Jun 2014 at 8:05