Trouble sending data via TCP socket

From: Date: Tue, 16 May 2006 02:15:35 +0000
Subject: Trouble sending data via TCP socket
Groups: php.general 
Request: Send a blank email to php-general+get-236260@lists.php.net to get a copy of this message
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); I'm supposed to get something like this in reply (taken from my desktop Jabber client's debug window): <?xml version='1.0'?> <stream:stream xmlns:stream='http://etherx.jabber.org/streams'
                 id='4468F937' xmlns='jabber:client'
                 from='jabber.org'>
Instead, I get this error message: <stream:error> <invalid-namespace
     xmlns='urn:ietf:params:xml:ns:xmpp-streams'/>
</stream:error> That I get a conformant Jabber error message suggests that I -am- at least connecting to the server properly, but that the data is not getting to the server intact. I am certain that the XML header is correct: I also tested another PHP Jabber implementation[1] with the same result, even though a search of this mailing list suggests that said implementation has been known to work for other people. Since I tested it on two different machines (my home Windows computer and a Linux Dreamhost Web server) using three different versions of PHP (PHP 5.1.4 Winodws CLI, PHP 4.3.3 Windows CLI, PHP 5.1.1 Linux FastCGI), it's pretty clear that it's not a bug in the version of PHP I initially tested on. I also tried connecting to three different Jabber servers (my private dark-phantasy server, jabber.org, and a test Wildfire server on my colleague's machine) and all three gave me similar errors (with differing levels of spec compliance...). In short, I am stumped. If anyone with some experience in these matters could shed some light on my problem I would be most grateful. [1] <http://cjphp.netflint.net/> -- J. King http://jking.dark-phantasy.com/

« previous php.general (#236260) next »