嘿伙计们,在向应用引擎的 xmpp 客户端发送消息时,我似乎在使用 xmpppy 客户端时遇到了问题。我没有收到任何错误。消息只是没有到达那里。从应用引擎的客户端向 sl4a 客户端发送消息是可行的。向 sl4a 客户端和从 google talk 客户端发送消息也可以正常工作。
任何帮助将不胜感激。
这是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))