общение с jabber-сервером

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
$JABBER_SERVER = "jabber.ru";
$PORT = 5222;
echo "<pre>";
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_connect($socket, $JABBER_SERVER, $PORT);
if(!$socket) { echo 'soket open - NO'; exit; }
else { echo 'socket open - OK<br>'; }
$t = "<stream:stream to='jabber.ru' xmlns='jabber:client' ";
$t .= "xmlns:stream='http://etherx.jabber.org/streams' xml:lang='ru' version='1.0'/>";
echo '<b>Клиент - </b>'.($t);
echo "\n\n";
socket_write($socket, $t);
$data = socket_read($socket, 1024);
echo '<b>Ответ от jabber - </b>'.$data."\n\n";
$t1 = "<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='DIGEST-MD5' />";
echo '<b>Клиент - </b>'.($t1);
echo "\n\n";
socket_write($socket, $t);
$data = socket_read($socket, 1024);
echo '<b>Ответ от jabber - </b>'.$data."\n\n";
socket_close($socket);
echo "</pre>";
echo "\n\n";