Re: Trouble sending data via TCP socket

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

 



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


[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