开发者

Python xmpppy client not sending message to appengine xmpp client

Hey Guys, I seem to be having trouble using the xmpppy client when sending messages to the app engine's xmpp client. I am not getting any errors. The messages just aren't arriving there. Sending messages from app engine's client to the sl4a client works. Sending messages to and from google talk's client to and from the sl4a client works as well.

Any help would be greatly appreciated.

Here is the python code

import xmpp
import time

_SERVER = 'talk.google.com', 5223
commandByXMPP()

def commandByXMPP():
  global xmppUsername
  xmppUsername = 'garrowsbot@gmail.com'  
  global xmppPassword
  xmppPassword = 'obscured'  
  global xmppClient
  global operator
  operator = "cellbotmote@appspot.com"

  jid = xmpp.protocol.JID(xmppUsername)
  xmppClient = xmpp.Client(jid.getDomain(), debug=[])
  xmppClient.connect(server=_SERVER)
  try:
    xmppClient.RegisterHandler('message', XMPP_message_cb)
  except:
    exitCellbot('XMPP error. You sure the phone has an internet connection?')
  if not xmppClient:
    exitCellbot('XMPP Connection failed!')
    return
  auth = xmppClient.auth(jid.getNode(), xmppPassword, 'botty')
  if not auth:
 开发者_开发知识库   exitCellbot('XMPP Authentication failed!')
    return
  xmppClient.sendInitPresence()
  print "XMPP username for the robot is:\n" + xmppUsername

  start=time.time()
  i=0
  try:
    outputToOperator("starting")
    while time.time()-start<15:
      print "tick"
      xmppClient.Process(1)
      i = i +1
      if i % 10 == 0:
        outputToOperator("hello")
    outputToOperator("exiting")
  except KeyboardInterrupt:
    pass


def XMPP_message_cb(session, message):
  jid = xmpp.protocol.JID(message.getFrom())
  global operator
  command = message.getBody()
  print command

def outputToOperator(msg):
  print "Outputting "+msg+" to " + operator
  xmppClient.send(xmpp.Message(operator, msg))


1) Check that garrowsbot@gmail.com is on the roster for cellbotmote@appspot.com. GTalk won't deliver messages from unknown users. 2) Send a message of type chat:

xmppClient.send(xmpp.Message(operator, msg, typ='chat'))

Some clients do not react well to receiving "normal" messages, which don't have a type attribute.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜