Re: Trouble sending data via TCP socket

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 5/16/06, J. King <jking@xxxxxxxxxxxxxxxxx> wrote:
To further my understanding of how Jabber works I have decided I should
try and write my own XMPP implementation in PHP.  However, I've run into
trouble rather quickly.

To connect to a Jabber server, one must open a TCP socket to the server
(typically through port 5269) send an XML-based stream header, wait for
the server's confirmation and then log in, etc.  As an initial test I
tried to open a TCP socket, send a stream header, get the server's
response, then disconnect.  I did so thusly:

   $server = "jabber.org"; //example server
   $port = 5269; //default port
   $nsStream = "http://etherx.jabber.org/streams";; // Streams namespace

   $socket = stream_socket_client("tcp://$server:$port");
   $header = "<stream:stream to='$server' xmlns='jabber:client'
xmlns:stream='$nsClient' xml:lang='en' version='1.0'>";
   fwrite($socket, $header); //send header
   echo stream_get_contents($socket); //get server confirmation

   //close connection
   fwrite($socket, "</stream:stream>");
   fclose($socket);

[snipped]

I played with your code and here are some observations:

Shouldn't that variable inside $header be $nsStream (and not
$nsClient)? Also, stream_get_contents may not be ideal here
since it tries to get the full contents of the stream (until EOF?),
so you should probably be using fread() here.

Another thing, the Jabber.org default port seems to be 5222
(class.jabber.php also uses that port).

Rabin

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux