PHP stream_socket_client和facebook聊天

时间:2011-03-27 14:16:38

标签: php facebook xmpp

$fp         = stream_socket_client("tcp://chat.facebook.com:5222", $errno, $errstr, 20);

fwrite($fp, '<stream:stream to="chat.facebook.com" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" version="1.0" />' . PHP_EOL);

$temp1      = fgets($fp);

fwrite($fp, '<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="X-FACEBOOK-PLATFORM"></auth>');

$temp2      = fgets($fp);

fclose($fp);

die(var_dump( $temp1, $temp2 ));

导致$ temp2 false结果的原因是什么?

    string(365) "<?xml version="1.0"?><stream:stream id="247B12CF" from="chat.facebook.com" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" version="1.0" xml:lang="en"><stream:features><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>X-FACEBOOK-PLATFORM</mechanism><mechanism>DIGEST-MD5</mechanism></mechanisms></stream:features></stream:stream>"
bool(false)

1 个答案:

答案 0 :(得分:0)

问题是您的stream:stream行应该只是一个开始标记,而不是完整元素。在第一次fwrite来电中删除/作为倒数第二个字符。当您发送完整的根元素而不是开始标记时,服务器正在断开连接。