Python xmppy客户端未向appengine xmpp clien发送消息

2024-04-25 23:21:12 发布

您现在位置:Python中文网/ 问答频道 /正文

嘿伙计们, 在向appengine的xmpp客户端发送消息时,我似乎在使用xmppy客户端时遇到了问题。 我没有收到任何错误。信息只是没有到达那里。 从app engine客户端向sl4a客户端发送消息是有效的。 在googletalk的客户端和sl4a客户端之间发送消息同样有效。在

任何帮助都将不胜感激。在

这是python代码

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))

Tags: com消息客户端messagetimedefxmppjid
1条回答
网友
1楼 · 发布于 2024-04-25 23:21:12

1)检查garrowsbot@gmail.com在花名册上cellbotmote@appspot.com。GTalk不会传递来自未知用户的消息。 2) 发送聊天类型的消息:

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

有些客户机对接收“普通”消息的反应不好,因为这些消息没有type属性。在

相关问题 更多 >