?

Log in

No account? Create an account
I'm just starting at all this socket stuff in my programming. But… - LiveJournal Client Discussions — LiveJournal [entries|archive|friends|userinfo]
LiveJournal Client Discussions

[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

[Aug. 2nd, 2006|12:09 am]
LiveJournal Client Discussions
lj_clients
[lilmuckers]
I'm just starting at all this socket stuff in my programming.
But anyway; i have a LJ module on my website, and i thought it would be really nifty to throw a little application so my users could update their LJs straight from my site. So i'm working on an LJ-Client in PHP.

I was trying the Get Challange method of authentication, but i can't seem to get a response back from the server when i send the request. the script sits there for 10 or 20 seconds and then claims that the server didn't send a response:

this is what my test script outputs:


TCP/IP Connection


OK.
Attempting to connect to '204.9.177.18' on port '80'...OK.
Request to be sent:
POST /interface/xmlrpc HTTP/1.0
User-Agent: XMLRPC Client 1.0
Host: www.livejournal.com
Content-Type: text/xml
Content-Length: 193

<?xml version="1.0"?>
<methodCall>
<methodName>LJ.XMLRPC.getchallenge</methodName>
<params>
<param>

</param>
</params>
</methodCall>
Connection: Close


Sending HTTP POST request...OK.
Reading response:


Closing socket...OK.



And this is the script itself:

<?php
error_reporting(E_ALL);

echo "<h2>TCP/IP Connection</h2><pre>\n";

/* Get the port for the WWW service. */
$service_port = getservbyname('www', 'tcp');

/* Get the IP address for the target host. */
$address = gethostbyname('www.livejournal.com');

/* Create a TCP/IP socket. */
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket < 0) {
echo "socket_create() failed: reason: " . socket_strerror($socket) . "\n";
} else {
echo "OK.\n";
}

echo "Attempting to connect to '$address' on port '$service_port'...";
$result = socket_connect($socket, $address, $service_port);
if ($result < 0) {
echo "socket_connect() failed.\nReason: ($result) " . socket_strerror($result) . "\n";
} else {
echo "OK.\n";
}

$in = "POST /interface/xmlrpc HTTP/1.0\r\n";
$in .= "User-Agent: XMLRPC Client 1.0\r\n";
$in .= "Host: www.livejournal.com\r\n";
$in .= "Content-Type: text/xml\r\n";
$in .= "Content-Length: 193 \r\n";
$in .= "\r\n";
$in .= "<?xml version=\"1.0\"?>\r\n";
$in .= "<methodCall>\r\n";
$in .= "<methodName>LJ.XMLRPC.getchallenge</methodName>\r\n";
$in .= "<params>\r\n";
$in .= "<param>\r\n";
$in .= "\r\n";
$in .= "</param>\r\n";
$in .= "</params>\r\n";
$in .= "</methodCall>\r\n";
$in .= "Connection: Close\r\n\r\n";

echo "Request to be sent:\r\n";
echo htmlspecialchars($in);
echo "\r\n";

$out = '';

echo "Sending HTTP POST request...";
socket_write($socket, $in, strlen($in));
echo "OK.\n";

echo "Reading response:\n\n";
while ($out = socket_read($socket, 2048)) {
echo htmlspecialchars($out);
}

echo "\r\nClosing socket...";
socket_close($socket);
echo "OK.\n\n</pre>";
?>



forgive me if this is a stupid question, this is my first dabble into sockets.

Oh, i'm aware there is an XML-RPC extension for PHP, however this is not compiled into the PHP on my server. (i'm noticing more and more how my server lacks extensions that would prove invaluable to extending my site how i wish. Oh well, i suppose that's what i get for a free high-bandwidth server)
linkReply

Comments:
From: lileja
2006-08-05 03:51 am (UTC)
<struct> i mean
(Reply) (Parent) (Thread)