准备用python做个gtalk的客户端
http://hi.baidu.com/bluebanboom/blog/item/b33fa8188812da0735fa4130.html
为了摆脱qq,就想自己写个gtalk的client,学习一哈python,呵呵,因为gtalk基于Jabber/XMPP,我又刚好找到了python下的XMPP的封装,图个简单,不过,还是要先了解XMPP协议才行.
XMPPY http://xmpppy.sf.net/
XMPP的RFC
XMPP Specs
The base specifications of the Extensible Messaging and Presence Protocol (XMPP) formalize the core protocols developed within the Jabber open-source community in 1999. They were produced by the IETF’s XMPP Working Group and published as RFCs in October, 2004.
Note: Only the ASCII version is normative!
RFC | Short Name | Formats | Description |
---|---|---|---|
RFC 3920 | XMPP Core | Text | HTML | XML streams, SASL, TLS, stringprep profiles, stanza semantics |
RFC 3921 | XMPP IM | Text | HTML | XMPP extensions for basic instant messaging and presence |
RFC 3922 | XMPP CPIM | Text | HTML | Mapping XMPP to the IETF’s CPIM specifications |
RFC 3923 | XMPP E2E | Text | HTML | End-to-end signing and object encryption for XMPP |
RFC 4622 | XMPP URI | Text (HTML to follow) | Internationalized Resource Identifiers (IRIs) and Uniform Resource Identifiers (URIs) for XMPP |
Many XMPP extensions are defined in the JEP series produced by the Jabber Software Foundation, and several XMPP-related Internet-Drafts are currently under consideration within the IETF.
进度:
08/05/2006
收集资料,准备中ing!
08/07/2006
学习使用xmpp,参照例子写了一个连接代码,不成功
代码如下:
===========================
import xmpp
jid = xmpp.protocol.JID(domain=’gmail.com’)
cl = xmpp.Client(jid.getDomain(),debug=[])
cl.connect((‘talk.google.com’,5222))
===========================
错误提示:
===========================
An error occurred while looking up _xmpp-client._tcp.talk.google.com
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "E:\Python24\lib\site-packages\xmpp\client.py", line 200, in connect
while not self.TLS.starttls and self.Process(1): pass
File "E:\Python24\lib\site-packages\xmpp\dispatcher.py", line 302, in dispatch
handler[‘func’](session,stanza)
File "E:\Python24\lib\site-packages\xmpp\transports.py", line 327, in StartTLSHandler
self._startSSL()
File "E:\Python24\lib\site-packages\xmpp\transports.py", line 305, in _startSSL
tcpsock._sslObj = socket.ssl(tcpsock._sock, None, None)
AttributeError: ‘module’ object has no attribute ‘ssl’
===========================
准备放弃xmpppy,打算自己封装协议
重新参照资料写了一个简单的代码
from socket import *
import sys
import os
s = socket()
s.connect((‘talk.google.com’,5222))
s.send(‘<stream:stream to="gmail.com" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams">\r\n’)
buf=2048
print s.recv(buf)
输出如下:
<stream:stream from="gmail.com" id="X5785D8E553038706" xmlns:stream="http://ethe
rx.jabber.org/streams" xmlns="jabber:client">
关于xmpp协议还没开始学习
2006-8-21
yes, it is working,when i use xmpp connect with gtalk.
i think when i first use xmpp,the err due to the python version i use.
it was ActivePython,in which,the socket do not support ssl!
but in the official version,there was a message showed by xmpp"An error occurred while looking up _xmpp-client._tcp.talk.google.com"
i don’t know why?but when i search in google.com,i got this site http://edge.nfshost.com/blog/2006/08/09/todosh-jabber-bot-v06/
here,i get some source usefull!
so, come on!
2006-8-22
import xmpp
jid = xmpp.protocol.JID(‘somebody@gmail.com’)
cl = xmpp.Client(jid.getDomain(),debug=[])
cl.connect((‘talk.google.com’,5222))
cl.auth(jid.getNode(),’password’)
Roster = cl.getRoster()
names = Roster.getItems()
for name in names:
status = Roster.getStatus(name)
show = Roster.getShow(name)
sb = Roster.getSubscription(name)
print name,status,show,sb
t = Roster.getStatus(‘bluebanboom@gmail.com’)
print t
ss = Roster.getItem(‘bluebanboom@gmail.com’)
print ss
cl.send(xmpp.protocol.Message(‘bluebanboom@gmail.com’,’hello’,typ="chat"))
2006.9.9
遇到了问题,网络不太好,经常性的登陆不了,而且,开发环境出了莫名其妙的问题,暂告一段落!
2006.9.10
聊天的时候发现了这个!!
抱歉,暂停评论。