Update: changed the client code and results to use the correct port (reversing a change I made while testing).

In your first client, you need to flush your output, otherwise nothing is sent to the server, and, as jethro said, you need two linefeeds between the headers and body of your request. You can try the following:

#!/usr/bin/perl use strict; use Socket; use IO::Handle; # initialize host and port my $host = 'localhost'; my $port = 8999; # my $port = 80; my $proto = getprotobyname('tcp'); # get the port address my $iaddr = inet_aton($host); my $paddr = sockaddr_in($port, $iaddr); # create the socket, connect to the port socket(SOCKET, PF_INET, SOCK_STREAM, $proto) or die "socket: $!"; connect(SOCKET, $paddr) or die "connect: $!"; SOCKET->autoflush(1); # create data my $data = <<"START" ; <?xml version="1.0"?> <methodCall> <methodName>sum</methodName> <params> <param> <value><double>1.12</double></value> </param> <param> <value><double>4.12</double></value> </param> </params> </methodCall> START my $header = <<"START" ; POST /quotes.cgi HTTP/1.0 Host: localhost Content-Type: text/xml START $header .= "Content-length: " . length($data) ; my $content = $header. "\n\n" . $data ; print $content ; print SOCKET "$content\n" or die "print SOCKET: $!"; print "waiting for response\n"; my $line; while ($line = <SOCKET> ) { print $line; } close SOCKET or die "close: $!";

On my system, this produces:

POST /quotes.cgi HTTP/1.0 Host: localhost Content-Type: text/xml Content-length: 209 <?xml version="1.0"?> <methodCall> <methodName>sum</methodName> <params> <param> <value><double>1.12</double></value> </param> <param> <value><double>4.12</double></value> </param> </params> </methodCall> waiting for response HTTP/1.1 403 Forbidden Date: Mon, 15 Dec 2008 16:09:28 GMT Server: libwww-perl-daemon/5.818 Content-Type: text/html Content-Length: 53 <title>403 Forbidden</title> <h1>403 Forbidden</h1>

I am not familiar with the Frontier XML RPC2 protocol, but looking at the server it appears your request must use the path /RPC2. From Frontier/Daemon.pm:

while ($conn = $self->accept) { my $rq = $conn->get_request; if ($rq) { if ($rq->method eq 'POST' && $rq->url->path eq '/RPC2') { ${*$self}{'response'}->content(${*$self}{'decode'}->se +rve($rq->content, ${*$self}{'methods'})); $conn->send_response(${*$self}{'response'}); } else { print STDERR "got an invalid request\n"; $conn->send_error(RC_FORBIDDEN); } } $conn->close; $conn = undef; # close connection }

Update: Change the path in your request to /RPC2 and it appears to work:

#!/usr/bin/perl use strict; use Socket; use IO::Handle; # initialize host and port my $host = 'localhost'; my $port = 8999; # my $port = 80; my $proto = getprotobyname('tcp'); # get the port address my $iaddr = inet_aton($host); my $paddr = sockaddr_in($port, $iaddr); # create the socket, connect to the port socket(SOCKET, PF_INET, SOCK_STREAM, $proto) or die "socket: $!"; connect(SOCKET, $paddr) or die "connect: $!"; SOCKET->autoflush(1); # create data my $data = <<"START" ; <?xml version="1.0"?> <methodCall> <methodName>sum</methodName> <params> <param> <value><double>1.12</double></value> </param> <param> <value><double>4.12</double></value> </param> </params> </methodCall> START my $header = <<"START" ; POST /RPC2 HTTP/1.0 Host: localhost Content-Type: text/xml START $header .= "Content-length: " . length($data) ; my $content = $header. "\n\n" . $data ; print $content ; print SOCKET "$content\n" or die "print SOCKET: $!"; print "waiting for response\n"; my $line; while ($line = <SOCKET> ) { print $line; } close SOCKET or die "close: $!";

produces

POST /RPC2 HTTP/1.0 Host: localhost Content-Type: text/xml Content-length: 209 <?xml version="1.0"?> <methodCall> <methodName>sum</methodName> <params> <param> <value><double>1.12</double></value> </param> <param> <value><double>4.12</double></value> </param> </params> </methodCall> waiting for response HTTP/1.1 200 OK Date: Mon, 15 Dec 2008 16:17:46 GMT Server: libwww-perl-daemon/5.818 Content-Length: 128 Content-Type: text/xml <?xml version="1.0"?> <methodResponse> <params> <param><value><double>5.24</double></value></param> </params> </methodResponse>

In reply to Re: XMLRPC - doing it the hard way by ig
in thread XMLRPC - doing it the hard way by jeanluca

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.