[英]How do I authenticate my XMPP client with the server?
我正在為一個大學項目編寫一個 XMPP 客戶端,該項目應該從其他客戶端發送和接收消息。 我對 XMPP 及其語法有基本的了解,但似乎無法連接到 gtalk 服務器。 免責聲明 - 我不能使用 Smack 或任何其他庫。
Socket s = new Socket("talk.l.google.com", 5222);
PrintWriter out = new PrintWriter(s.getOutputStream());
out.println("<?xml version='1.0' encoding='utf-8' ?>");
out.println("<stream:stream "
+ "xmlns='jabber:client' "
+" from='example@gmail.com' to='gmail.com' "
+ " xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>");
out.flush();
我假設連接成功,因為我收到了這個響應:
<stream:stream from="gmail.com" id="E3A7EFC5647601B3" version="1.0" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client"><stream:features><starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"><required/></starttls><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>X-OAUTH2</mechanism><mechanism>X-GOOGLE-TOKEN</mechanism></mechanisms></stream:features>
如果我嘗試發送一些 xml 數據包,例如,一條消息,我顯然會得到一個
<stream:error><not-authorized xmlns="urn:ietf:params:xml:ns:xmpp-streams"/></stream:error>
我像這樣發送消息:
out.println("<message to='07xcpozn829nd25ivx1gpp3dug@public.talk.google.com'"
+"from='example@gmail.com'>\r\n"
+"<body>Wherefore art thou?</body>\r\n"
+"</message>");
I: <?xml version='1.0'?>
<stream:stream
from='juliet@im.example.com'
to='im.example.com'
version='1.0'
xml:lang='en'
xmlns='jabber:client'
xmlns:stream='http://etherx.jabber.org/streams'>
R: <?xml version='1.0'?>
<stream:stream
from='im.example.com'
id='++TR84Sm6A3hnt3Q065SnAbbk3Y='
to='juliet@im.example.com'
version='1.0'
xml:lang='en'
xmlns='jabber:client'
xmlns:stream='http://etherx.jabber.org/streams'>
您一定在 SASL 協商期間錯過了身份驗證部分。
檢查第9.1章。 https://datatracker.ietf.org/doc/rfc6120/ 中的客戶端到服務器示例
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.