XMPPPy work with Openfire

I was working on python xmpp library (XMPPPy) with Openfire. It could connect, send message and recieve message. But the problem is the xmpppy client will get following exception after every 5 or 6 minutes:

DEBUG: socket error Socket error while receiving data
Traceback (most recent call last):
File “/root/workspace/MyTest/src/xmpp/transports.py”, line 146, in receive
try: received = self._recv(BUFLEN)
sslerror: (6, ‘TLS/SSL connection has been closed’)
DEBUG: client stop Disconnect detected
DEBUG: socket error Socket operation failed
DEBUG: socket error Socket error while receiving data

The only recommend I got is use another xmpp server instead of Openfire. I am just wondering this is the xmpppy problem or Openfire? Is there any way can make them work together?

Absolutely same problem here. My client disconnects after 5-6 minutes of inactivity with same error message. Any help will be greatly appretiated.

+1

6 minutes

not sure this will help, but I believe the code may have to send an ‘available’ status message every so often…some code I have running sends an ‘available’ presence packet every minute or so…seems to run ok 24x7. I think the version of xmpppy I’m using is 0.4.0.

this is my example code:

from xmpp import *

def StepOn(conn):

try:

  1. Event reconnection doesn’t work

#if not conn.isConnected():

  1. conn.reconnectAndReauth()

  2. conn.sendInitPresence()

conn.Process(1)

except:

return 0

return 1

def GoOn(conn):

while StepOn(conn):

pass

def messageHandler(conn,mess_node):

print mess_node

#Born a client

cl=Client(‘client1’)

#connect it to SSL port directly

if not cl.connect(server=(openfire_server,5223)):

raise IOError(‘Can not connect to server.’)

#authorize client

if not cl.auth(‘client1’,‘123456’):

raise IOError(‘Can not auth with server.’)

#register some handlers (if you will register them before auth they will be thrown away)cl.RegisterHandler(‘message’,messageHandler)

#become availablecl.sendInitPresence()

#work some timecl.Process(1)

#if connection is brocken - restore itif not cl.isConnected(): cl.reconnectAndReauth()

#send an ASCII message, this one is workingcl.send(Message(‘client2@openfire_server’,‘Test message’))

GoOn(cl)

anything wrong here?

at the risk of exposing my poor code to ridicule…here’s the code I’m using to take messages from an mq series queue (message is an email message) and post it to a chat room on my local OpenFire server…we use internally for application notifications, etc. The mainloop is in the gchat class…I found that in order for the bot not to be disconnected, it had to send ‘Available’ presence messages every so often…so I put a counter in to do that nominally every 60 iterations of the ‘StepOn’ code.

@drwatterworth, thanks for your help and script. Yes, it works, keep sending message can keep the connection.

But I don’t think this is the right way to do in any production…

Is there anything else we can do about this problem?

I had the same issues, I created this function to deal with it:

#Time between sending keep alives, in seconds:

keepalive = 30

def JabberPing(last_time):

try:

client.Process(1)

now = int(time.strftime(’%s’, time.localtime()))

delta = now - last_time

if delta > keepalive:

client.send(’ ')

return(now)

else:

return(last_time)

except Exception:

sys.exit(1)

And I have this in my while loop:

JabberPing()

http://www.xmpp.org/extensions/xep-0040.html#sect-id2261340

Take a look at this for idle component sessions:
http://ralphm.jaiku.com/presence/36670416