XMPPHP 到 Openfire:发送消息似乎没问题,但目标没有收到它
XMPPHP to Openfire: Send message seems OK but target doesn't receive it
我的代码如下:
$conn = new XMPPHP_XMPP('localhost', 5222, 'pidgin', 'pidgin', 'xmpphp', 'localhost', $printlog=true, $loglevel=XMPPHP_Log::LEVEL_VERBOSE);
$conn->connect();
$conn->processUntil('session_start');
$conn->presence('Hello I am here');
$conn->useEncryption(false);
$conn->message('podgon', 'Test Message');
$payloads = $conn->processUntil('message');
$conn->disconnect();
看起来真的很管用。我的用户 podgon
在我的计算机上登录了 Spark,我可以在那里看到 pidgin
在线并在之后立即断开连接。
问题是:消息好像发送了,但是podgon
没有收到。
查看我的 LEVEL_VERBOSE
日志:
1420723347 [INFO]: Connecting to tcp://localhost:5222
1420723347 [VERBOSE]: Socket is ready; send it.
1420723347 [VERBOSE]: SENT: <stream:stream to="localhost" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" version="1.0">
1420723347 [VERBOSE]: Successfully sent 114 bytes.
1420723347 [VERBOSE]: RECV: <?xml version='1.0' encoding='UTF-8'?><stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" from="ubuntu-latitude-e5430-non-vpro" id="aea96a2c" xml:lang="en" version="1.0">
1420723347 [VERBOSE]: RECV: <stream:features><starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"></starttls><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>DIGEST-MD5</mechanism><mechanism>PLAIN</mechanism><mechanism>ANONYMOUS</mechanism><mechanism>CRAM-MD5</mechanism></mechanisms><compression xmlns="http://jabber.org/features/compress"><method>zlib</method></compression><auth xmlns="http://jabber.org/features/iq-auth"/><register xmlns="http://jabber.org/features/iq-register"/></stream:features>
1420723347 [DEBUG]: Calling features_handler
1420723347 [VERBOSE]: Socket is ready; send it.
1420723347 [VERBOSE]: SENT: <starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'><required /></starttls>
1420723347 [VERBOSE]: Successfully sent 73 bytes.
1420723347 [VERBOSE]: RECV: <proceed xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>
1420723347 [DEBUG]: Calling tls_proceed_handler
1420723347 [INFO]: Starting TLS encryption
1420723347 [VERBOSE]: Socket is ready; send it.
1420723347 [VERBOSE]: SENT: <stream:stream to="localhost" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" version="1.0">
1420723347 [VERBOSE]: Successfully sent 114 bytes.
1420723347 [VERBOSE]: RECV: <?xml version='1.0' encoding='UTF-8'?><stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" from="ubuntu-latitude-e5430-non-vpro" id="aea96a2c" xml:lang="en" version="1.0"><stream:features><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>DIGEST-MD5</mechanism><mechanism>PLAIN</mechanism><mechanism>ANONYMOUS</mechanism><mechanism>CRAM-MD5</mechanism></mechanisms><compression xmlns="http://jabber.org/features/compress"><method>zlib</method></compression><auth xmlns="http://jabber.org/features/iq-auth"/><register xmlns="http://jabber.org/features/iq-register"/></stream:features>
1420723347 [DEBUG]: Calling features_handler
1420723347 [INFO]: Attempting Auth...
1420723347 [VERBOSE]: Socket is ready; send it.
1420723347 [VERBOSE]: SENT: <auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>AHBpZGdpbgBwaWRnaW4=</auth>
1420723347 [VERBOSE]: Successfully sent 92 bytes.
1420723347 [VERBOSE]: RECV: <success xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/>
1420723347 [DEBUG]: Calling sasl_success_handler
1420723347 [INFO]: Auth success!
1420723347 [VERBOSE]: Socket is ready; send it.
1420723347 [VERBOSE]: SENT: <stream:stream to="localhost" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" version="1.0">
1420723347 [VERBOSE]: Successfully sent 114 bytes.
1420723347 [VERBOSE]: RECV: <?xml version='1.0' encoding='UTF-8'?><stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" from="ubuntu-latitude-e5430-non-vpro" id="aea96a2c" xml:lang="en" version="1.0"><stream:features><compression xmlns="http://jabber.org/features/compress"><method>zlib</method></compression><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"/><session xmlns="urn:ietf:params:xml:ns:xmpp-session"/></stream:features>
1420723347 [DEBUG]: Calling features_handler
1420723347 [VERBOSE]: Socket is ready; send it.
1420723347 [VERBOSE]: SENT: <iq xmlns="jabber:client" type="set" id="1"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><resource>xmpphp</resource></bind></iq>
1420723347 [VERBOSE]: Successfully sent 130 bytes.
1420723347 [VERBOSE]: RECV: <iq type="result" id="1" to="ubuntu-latitude-e5430-non-vpro/aea96a2c"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>pidgin@ubuntu-latitude-e5430-non-vpro/xmpphp</jid></bind></iq>
1420723347 [INFO]: Bound to pidgin@ubuntu-latitude-e5430-non-vpro/xmpphp
1420723347 [VERBOSE]: Socket is ready; send it.
1420723347 [VERBOSE]: SENT: <iq xmlns='jabber:client' type='set' id='2'><session xmlns='urn:ietf:params:xml:ns:xmpp-session' /></iq>
1420723347 [VERBOSE]: Successfully sent 104 bytes.
1420723347 [VERBOSE]: RECV: <iq type="result" id="2" to="pidgin@ubuntu-latitude-e5430-non-vpro/xmpphp"/>
1420723347 [INFO]: Session started
1420723347 [DEBUG]: EVENT: session_start
1420723347 [VERBOSE]: Socket is ready; send it.
1420723347 [VERBOSE]: SENT: <presence><status>Hello I am here</status></presence>
1420723347 [VERBOSE]: Successfully sent 53 bytes.
1420723347 [VERBOSE]: Socket is ready; send it.
1420723347 [VERBOSE]: SENT: <message from="pidgin@ubuntu-latitude-e5430-non-vpro/xmpphp" to="podgon" type='chat'><body>Test Message</body></message>
1420723347 [VERBOSE]: Successfully sent 120 bytes.
1420723347 [VERBOSE]: RECV: <presence from="pidgin@ubuntu-latitude-e5430-non-vpro/Monal" to="pidgin@ubuntu-latitude-e5430-non-vpro/xmpphp"><c xmlns="http://jabber.org/protocol/caps" ext="pmuc-v1 voice-v1" hash="sha-1" node="http://monal.im/caps"/></presence>
1420723347 [DEBUG]: Calling presence_handler
1420723347 [DEBUG]: Presence: pidgin@ubuntu-latitude-e5430-non-vpro/Monal [available]
1420723347 [DEBUG]: EVENT: presence
1420723347 [VERBOSE]: RECV: <presence from="pidgin@ubuntu-latitude-e5430-non-vpro/xmpphp" to="pidgin@ubuntu-latitude-e5430-non-vpro/xmpphp"><status>Hello I am here</status></presence>
1420723347 [DEBUG]: Calling presence_handler
1420723347 [DEBUG]: Presence: pidgin@ubuntu-latitude-e5430-non-vpro/xmpphp [available] Hello I am here
1420723347 [DEBUG]: EVENT: presence
1420723347 [VERBOSE]: RECV: <presence id="9A9T8-6" from="podgon@ubuntu-latitude-e5430-non-vpro/Spark 2.6.3" to="pidgin@ubuntu-latitude-e5430-non-vpro/xmpphp"><status>Online</status><priority>1</priority><c xmlns="http://jabber.org/protocol/caps" node="jitsi-jingle" ver="0.1" ext=""/></presence>
1420723347 [DEBUG]: Calling presence_handler
1420723347 [DEBUG]: Presence: podgon@ubuntu-latitude-e5430-non-vpro/Spark 2.6.3 [available] Online
1420723347 [DEBUG]: EVENT: presence
1420723347 [VERBOSE]: RECV: <message to="pidgin@ubuntu-latitude-e5430-non-vpro/xmpphp" from="podgon" type="error"><error code="404" type="cancel"><remote-server-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></message>
1420723347 [DEBUG]: Calling message_handler
1420723347 [DEBUG]: Message:
1420723347 [DEBUG]: EVENT: message
1420723347 [VERBOSE]: Disconnecting...
1420723347 [VERBOSE]: Socket is ready; send it.
1420723347 [VERBOSE]: SENT: </stream:stream>
1420723347 [VERBOSE]: Successfully sent 16 bytes.
1420723347 [VERBOSE]: RECV: </stream:stream>
1420723347 [DEBUG]: EVENT: end_stream
为什么这不起作用,我该如何解决?谢谢
您正在将邮件发送至 podgon
,但您应该将其发送至 podgon@ubuntu-latitude-e5430-non-vpro
。
与电子邮件不同,没有主机名的 JID 不会使用默认主机名进行扩展,而是被视为服务器的 JID:当您向 podgon
发送消息时,您的服务器会尝试解析 podgon
通过 DNS 并连接到该主机上的 XMPP 服务器。
我的代码如下:
$conn = new XMPPHP_XMPP('localhost', 5222, 'pidgin', 'pidgin', 'xmpphp', 'localhost', $printlog=true, $loglevel=XMPPHP_Log::LEVEL_VERBOSE);
$conn->connect();
$conn->processUntil('session_start');
$conn->presence('Hello I am here');
$conn->useEncryption(false);
$conn->message('podgon', 'Test Message');
$payloads = $conn->processUntil('message');
$conn->disconnect();
看起来真的很管用。我的用户 podgon
在我的计算机上登录了 Spark,我可以在那里看到 pidgin
在线并在之后立即断开连接。
问题是:消息好像发送了,但是podgon
没有收到。
查看我的 LEVEL_VERBOSE
日志:
1420723347 [INFO]: Connecting to tcp://localhost:5222
1420723347 [VERBOSE]: Socket is ready; send it.
1420723347 [VERBOSE]: SENT: <stream:stream to="localhost" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" version="1.0">
1420723347 [VERBOSE]: Successfully sent 114 bytes.
1420723347 [VERBOSE]: RECV: <?xml version='1.0' encoding='UTF-8'?><stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" from="ubuntu-latitude-e5430-non-vpro" id="aea96a2c" xml:lang="en" version="1.0">
1420723347 [VERBOSE]: RECV: <stream:features><starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"></starttls><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>DIGEST-MD5</mechanism><mechanism>PLAIN</mechanism><mechanism>ANONYMOUS</mechanism><mechanism>CRAM-MD5</mechanism></mechanisms><compression xmlns="http://jabber.org/features/compress"><method>zlib</method></compression><auth xmlns="http://jabber.org/features/iq-auth"/><register xmlns="http://jabber.org/features/iq-register"/></stream:features>
1420723347 [DEBUG]: Calling features_handler
1420723347 [VERBOSE]: Socket is ready; send it.
1420723347 [VERBOSE]: SENT: <starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'><required /></starttls>
1420723347 [VERBOSE]: Successfully sent 73 bytes.
1420723347 [VERBOSE]: RECV: <proceed xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>
1420723347 [DEBUG]: Calling tls_proceed_handler
1420723347 [INFO]: Starting TLS encryption
1420723347 [VERBOSE]: Socket is ready; send it.
1420723347 [VERBOSE]: SENT: <stream:stream to="localhost" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" version="1.0">
1420723347 [VERBOSE]: Successfully sent 114 bytes.
1420723347 [VERBOSE]: RECV: <?xml version='1.0' encoding='UTF-8'?><stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" from="ubuntu-latitude-e5430-non-vpro" id="aea96a2c" xml:lang="en" version="1.0"><stream:features><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>DIGEST-MD5</mechanism><mechanism>PLAIN</mechanism><mechanism>ANONYMOUS</mechanism><mechanism>CRAM-MD5</mechanism></mechanisms><compression xmlns="http://jabber.org/features/compress"><method>zlib</method></compression><auth xmlns="http://jabber.org/features/iq-auth"/><register xmlns="http://jabber.org/features/iq-register"/></stream:features>
1420723347 [DEBUG]: Calling features_handler
1420723347 [INFO]: Attempting Auth...
1420723347 [VERBOSE]: Socket is ready; send it.
1420723347 [VERBOSE]: SENT: <auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>AHBpZGdpbgBwaWRnaW4=</auth>
1420723347 [VERBOSE]: Successfully sent 92 bytes.
1420723347 [VERBOSE]: RECV: <success xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/>
1420723347 [DEBUG]: Calling sasl_success_handler
1420723347 [INFO]: Auth success!
1420723347 [VERBOSE]: Socket is ready; send it.
1420723347 [VERBOSE]: SENT: <stream:stream to="localhost" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" version="1.0">
1420723347 [VERBOSE]: Successfully sent 114 bytes.
1420723347 [VERBOSE]: RECV: <?xml version='1.0' encoding='UTF-8'?><stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" from="ubuntu-latitude-e5430-non-vpro" id="aea96a2c" xml:lang="en" version="1.0"><stream:features><compression xmlns="http://jabber.org/features/compress"><method>zlib</method></compression><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"/><session xmlns="urn:ietf:params:xml:ns:xmpp-session"/></stream:features>
1420723347 [DEBUG]: Calling features_handler
1420723347 [VERBOSE]: Socket is ready; send it.
1420723347 [VERBOSE]: SENT: <iq xmlns="jabber:client" type="set" id="1"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><resource>xmpphp</resource></bind></iq>
1420723347 [VERBOSE]: Successfully sent 130 bytes.
1420723347 [VERBOSE]: RECV: <iq type="result" id="1" to="ubuntu-latitude-e5430-non-vpro/aea96a2c"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>pidgin@ubuntu-latitude-e5430-non-vpro/xmpphp</jid></bind></iq>
1420723347 [INFO]: Bound to pidgin@ubuntu-latitude-e5430-non-vpro/xmpphp
1420723347 [VERBOSE]: Socket is ready; send it.
1420723347 [VERBOSE]: SENT: <iq xmlns='jabber:client' type='set' id='2'><session xmlns='urn:ietf:params:xml:ns:xmpp-session' /></iq>
1420723347 [VERBOSE]: Successfully sent 104 bytes.
1420723347 [VERBOSE]: RECV: <iq type="result" id="2" to="pidgin@ubuntu-latitude-e5430-non-vpro/xmpphp"/>
1420723347 [INFO]: Session started
1420723347 [DEBUG]: EVENT: session_start
1420723347 [VERBOSE]: Socket is ready; send it.
1420723347 [VERBOSE]: SENT: <presence><status>Hello I am here</status></presence>
1420723347 [VERBOSE]: Successfully sent 53 bytes.
1420723347 [VERBOSE]: Socket is ready; send it.
1420723347 [VERBOSE]: SENT: <message from="pidgin@ubuntu-latitude-e5430-non-vpro/xmpphp" to="podgon" type='chat'><body>Test Message</body></message>
1420723347 [VERBOSE]: Successfully sent 120 bytes.
1420723347 [VERBOSE]: RECV: <presence from="pidgin@ubuntu-latitude-e5430-non-vpro/Monal" to="pidgin@ubuntu-latitude-e5430-non-vpro/xmpphp"><c xmlns="http://jabber.org/protocol/caps" ext="pmuc-v1 voice-v1" hash="sha-1" node="http://monal.im/caps"/></presence>
1420723347 [DEBUG]: Calling presence_handler
1420723347 [DEBUG]: Presence: pidgin@ubuntu-latitude-e5430-non-vpro/Monal [available]
1420723347 [DEBUG]: EVENT: presence
1420723347 [VERBOSE]: RECV: <presence from="pidgin@ubuntu-latitude-e5430-non-vpro/xmpphp" to="pidgin@ubuntu-latitude-e5430-non-vpro/xmpphp"><status>Hello I am here</status></presence>
1420723347 [DEBUG]: Calling presence_handler
1420723347 [DEBUG]: Presence: pidgin@ubuntu-latitude-e5430-non-vpro/xmpphp [available] Hello I am here
1420723347 [DEBUG]: EVENT: presence
1420723347 [VERBOSE]: RECV: <presence id="9A9T8-6" from="podgon@ubuntu-latitude-e5430-non-vpro/Spark 2.6.3" to="pidgin@ubuntu-latitude-e5430-non-vpro/xmpphp"><status>Online</status><priority>1</priority><c xmlns="http://jabber.org/protocol/caps" node="jitsi-jingle" ver="0.1" ext=""/></presence>
1420723347 [DEBUG]: Calling presence_handler
1420723347 [DEBUG]: Presence: podgon@ubuntu-latitude-e5430-non-vpro/Spark 2.6.3 [available] Online
1420723347 [DEBUG]: EVENT: presence
1420723347 [VERBOSE]: RECV: <message to="pidgin@ubuntu-latitude-e5430-non-vpro/xmpphp" from="podgon" type="error"><error code="404" type="cancel"><remote-server-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></message>
1420723347 [DEBUG]: Calling message_handler
1420723347 [DEBUG]: Message:
1420723347 [DEBUG]: EVENT: message
1420723347 [VERBOSE]: Disconnecting...
1420723347 [VERBOSE]: Socket is ready; send it.
1420723347 [VERBOSE]: SENT: </stream:stream>
1420723347 [VERBOSE]: Successfully sent 16 bytes.
1420723347 [VERBOSE]: RECV: </stream:stream>
1420723347 [DEBUG]: EVENT: end_stream
为什么这不起作用,我该如何解决?谢谢
您正在将邮件发送至 podgon
,但您应该将其发送至 podgon@ubuntu-latitude-e5430-non-vpro
。
与电子邮件不同,没有主机名的 JID 不会使用默认主机名进行扩展,而是被视为服务器的 JID:当您向 podgon
发送消息时,您的服务器会尝试解析 podgon
通过 DNS 并连接到该主机上的 XMPP 服务器。