我正在PC上运行ejabberd。当我尝试使用smack库将其与Android连接时,出现连接问题。
我正在使用converse.js与之连接,并且运行良好。
Android代码如下所示:
BOSHConfiguration conf = BOSHConfiguration.builder()
.setUsernameAndPassword("test@desktop-9ell91c", "12345")
.setFile("/http-bind/")
.setHost("192.168.225.83")
.setPort(5443)
.setXmppDomain(JidCreate.domainBareFrom("desktop-9ell91c"))
.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
.build();
XMPPBOSHConnection connection = new XMPPBOSHConnection(conf);
connection.connect();
connection.disconnect();
ejabberd的配置为:
port: 5443
module: ejabberd_http
request_handlers:
"/api": mod_http_api
"/bosh": mod_bosh
"/upload": mod_http_upload
"/ws": ejabberd_http_ws
"/oauth": ejabberd_oauth
web_admin: true
http_bind: true
captcha: false
tls: false
在调试中,它显示为:
2019-03-29 16:34:50.982 3564-3840/com.example.chat D/NetworkSecurityConfig: No Network Security Config specified, using platform default
2019-03-29 16:34:50.989 3564-3840/com.example.chat I/BOSHClient: Starting with 1 request processors
2019-03-29 16:34:51.014 3564-3842/com.example.chat I/System.out: isEmailSend:POST
2019-03-29 16:34:51.014 3564-3842/com.example.chat I/System.out: getAllHeaders:POST
2019-03-29 16:34:51.017 3564-3842/com.example.chat I/System.out: httpHeader:Content-Type: text/xml; charset=utf-8
2019-03-29 16:34:51.121 3564-3843/com.example.chat D/SMACK: RECV (0): <body xmpp:version='1.0' authid='17399078112278266584' xmlns='http://jabber.org/protocol/httpbind' sid='89daf51229fa6259ceb0830dd4f0f10aeee0a237' wait='60' ver='1.11' polling='2' inactivity='30' hold='1' xmpp:restartlogic='true' requests='2' secure='true' maxpause='120' xmlns:xmpp='urn:xmpp:xbosh' xmlns:stream='http://etherx.jabber.org/streams' from='desktop-9ell91c'><stream:features><mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'><mechanism>DIGEST-MD5</mechanism><mechanism>PLAIN</mechanism><mechanism>SCRAM-SHA-1</mechanism><mechanism>X-OAUTH2</mechanism></mechanisms><register xmlns='http://jabber.org/features/iq-register'/></stream:features></body>
2019-03-29 16:34:51.229 3564-3844/com.example.chat I/System.out: isEmailSend:POST
2019-03-29 16:34:51.229 3564-3844/com.example.chat I/System.out: getAllHeaders:POST
2019-03-29 16:34:51.229 3564-3844/com.example.chat I/System.out: httpHeader:Content-Type: text/xml; charset=utf-8
2019-03-29 16:35:21.175 3564-3844/com.example.chat W/AbstractXMPPConnection: Connection XMPPBOSHConnection[not-authenticated] (0) closed with error
org.igniterealtime.jbosh.BOSHException: Terminal binding condition encountered: remote-stream-error (Encapsulated transport protocol error.)
at org.igniterealtime.jbosh.BOSHClient.checkForTerminalBindingConditions(BOSHClient.java:1393)
at org.igniterealtime.jbosh.BOSHClient.processExchange(BOSHClient.java:1169)
at org.igniterealtime.jbosh.BOSHClient.processMessages(BOSHClient.java:998)
at org.igniterealtime.jbosh.BOSHClient.access$300(BOSHClient.java:100)
at org.igniterealtime.jbosh.BOSHClient$RequestProcessor.run(BOSHClient.java:1727)
at java.lang.Thread.run(Thread.java:764)