Patrick The Wierdo (lilmuckers) wrote in lj_clients,
Patrick The Wierdo

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

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

<?xml version="1.0"?>

Connection: Close

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

Closing socket...OK.

And this is the script itself:


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('');

/* 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:\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...";
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)

  • 302: lj_dev

    In the interests of consolidating all LiveJournal development-related discussion, we're going to be closing down this community. The same…

  • Plain text to LJ

    I have an old blog from xanga that's in html/plain text and I want to move it over here. Which client would be the best to do this? I also want to…

  • ljKlient 0.2.0 Preview Release 1

    Today marks another milestone in the development of ljKlient — as the first preview of the 0.2 series is released.  Please go to the project…

  • Post a new comment


    Comments allowed for members only

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened