2012-07-05 4 views
0

누구든지이 코드를 수정하는 데 도움이 될 수 있습니까? 실제로 필요하지만 다음에 무엇을해야할지 모를 수 있습니다. groupchat을 만들어 초대 된 사람에게 messega를 보내야합니다. 이제 [email protected]이 되겠지만, 그렇지 않습니다.
실수가 있습니까?python xmpppy를 사용하여 gtalk에서 MUC를 생성하는 방법

#!/usr/bin/python 
import sys,os,xmpp,time           
jid = '[email protected]' 
psw = 'psw' 
jid=xmpp.protocol.JID(jid) 
cl=xmpp.Client(jid.getDomain(),debug=[]) 
cl.connect() 
cl.auth(jid.getNode(),psw) 
node = jid.getNode() 
domain = 'talk.google.com' 
room = node + '@' + domain 
nroom = room + '/' + 'Maria' 
mes = xmpp.Presence(to=nroom) 
cl.sendInitPresence() 
cl.send(mes) 


NS_MUCUSER = 'http://jabber.org/protocol/muc#user' 
invite = xmpp.simplexml.Node('invite') 
invite.setAttr('to', '[email protected]') 
invite.setTagData('reason', 'I really need it!') 
mess = xmpp.Message(to=room) 
mess.setTag('x', namespace=NS_MUCUSER).addChild(node=invite) 
cl.send(mess) 


msg = xmpp.protocol.Message(body="Hello there!") 
msg.setTo(room) 
msg.setType('groupchat') 
cl.send(msg) 
time.sleep(1) # some older servers will not send the message if you disconnect immediately after sending 
cl.disconnect() 
print "Done" 
+0

안녕하세요 마리아, 당신이 지금까지 해 온 것을 보여 주면 더 좋은 품질의 답변을 얻을 수 있습니다 - 혼란 스러움을 보여주는 코드 스 니펫. – aychedee

+0

여기에 실수가 있다는 것을 알지만, 할 수있는 것은 모두 ... – Maria

답변

0

내 실수를 찾았습니다. 문제는 내가 서버에서 응답을 받기에 충분하지 않고 서버가 채팅 룸을 만들 수있게되기 전에 사람들을 초대했기 때문입니다. 이제 서버에서 응답을 받고 초대 메시지를 보낼 때까지 기다립니다.

0

사양에 따르면 - http://xmpp.org/extensions/xep-0045.html#createroom - 같은 방을 생성 및 구성을위한 워크 플로우가 같다

(또는 MUC)을 그 방을 만들어야합니다 존재하지 않는 공간을 가입 요청을 전송 다음 :

The user sends presence to <[email protected]/nick> and signal his or her support 
for the Multi-User Chat protocol by including extended presence information 
in an empty <x/> child element qualified by the 'http://jabber.org/protocol/muc' 
namespace (note the lack of an '#owner' or '#user' fragment). 

If this user is allowed to create a room and the room does not yet exist, the 
service MUST create the room according to some default configuration, assign the 
requesting user as the initial room owner, and add the owner to the room but not 
allow anyone else to enter the room (effectively "locking" the room). The initial 
presence stanza received by the owner from the room MUST include extended 
presence information indicating the user's status as an owner and acknowledging 
that the room has been created (via status code 201) and is awaiting 
configuration. 

그래서 이런 일이 다큐에 따라 작업을을 생각한다 mentation.

jid=xmpp.protocol.JID('[email protected]') 
cl=xmpp.Client(jid.getDomain(),debug=[]) 

jid = xmpp.protocol.JID('[email protected]') 
client = xmpp.Client(jid.getDomain(), debug=[]) 
client.connect() 
client.auth(jid.getNode(), 'my secret password') 
client.send(xmpp.Presence(to='[email protected]/ANick') 
+0

방 이름을 얻는 방법을 모르겠다. 모든 사람들에게 어떻게 메시지를 보낼 수 있습니까? 먼저 초대해야합니까? 그들이 내 명단에 있어야할까요? '내 방/내 닉'을 대체 할 수있는 예를 들어 주시겠습니까? – Maria

+0

http://xmpp.org/extensions/xep-0045.html에서 사양을 확인할 수 있습니다. – aychedee