[PyXMPP] Problem with Simple XMPP Client/Server
comsatcat
comsatcat at gmail.com
Mon Oct 6 00:21:07 CEST 2008
Hello,
I'm just learning the API so I'm sorry if this post has an answer already :)
I've written the following client:
from pyxmpp.jid import JID
from pyxmpp.jabber.all import Client
my_jid = JID("ben", "localhost", "master")
class AClient(Client):
def authorized(self):
print "I'm now authorized"
def connected(self):
print "I'm now connected"
if __name__ == "__main__":
client = AClient(jid=my_jid, password=u"foobar", server="localhost",
port=5222, auth_methods=["plain"])
client.connect()
client.loop(1)
And have written the corresponding server:
import socket
from pyxmpp.clientstream import ClientStream
from pyxmpp.all import JID
accounts = {"ben": "foobar"}
class Stream(ClientStream):
def
get_password(self,username,realm=None,acceptable_formats=("plain",)):
if "plain" in acceptable_formats and accounts.has_key(username):
return accounts[username],"plain"
return None,None
if __name__ == "__main__":
# create our jabber stream server
stream = Stream(JID("master", "localhost", "master"),
auth_methods=("plain"))
# create our socket
sock = socket.socket()
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind(("127.0.0.1", 5222))
sock.listen(1)
# accept connections and hand off to stream looper
while 1:
stream.accept(sock)
stream.loop(1)
However when I run the client to connect to the server I get the following
backtrace:
raise FatalStreamError,'Bad "to"'
pyxmpp.streambase.FatalStreamError: Bad "to"
I don't see much info the api documentation that explains whats going on...
I pulled this code straight out of the examples/ directory so not sure why
its not working.
Could someone possibly explain whats going on and how to fix this problem
and what would be even cooler is a pretty decent example of a working
server.
Thanks in advance,
Ben
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jajcus.net/pipermail/pyxmpp/attachments/20081005/d4bafc8c/attachment.html
More information about the PyXMPP
mailing list