Re: [PHP] Trouble sending data via TCP socket
On Mon, 15 May 2006, J. King 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'; [snip] stream:error invalid-namespace xmlns='urn:ietf:params:xml:ns:xmpp-streams'/ /stream:error What's the value of $nsClient??? I doesn't look like it's defined at all, so I would guess that your problem is there. -- 21:50:04 up 2 days, 9:07, 0 users, load average: 0.92, 0.37, 0.18 - Lic. Martín Marqués | SELECT 'mmarques' || Centro de Telemática| '@' || 'unl.edu.ar'; Universidad Nacional| DBA, Programador, del Litoral | Administrador - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Trouble sending data via TCP socket
On Mon, May 15, 2006 9:15 pm, J. King 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'; You might maybe need a newline after all that. And I'd double-check that XML lets you use ' instead of for attribut values, or whatever they are called, cuz I've only ever seen that I can recall. 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/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Trouble sending data via TCP socket
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/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Trouble sending data via TCP socket
On 5/16/06, J. King [EMAIL PROTECTED] 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