Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

No idea how to do XML-RPC

Pru Costello
Not My President
Join date: 5 Jun 2005
Posts: 25
08-02-2005 03:04
i've been trying for a while now to get XML-RPC working but everything i try doesn't work, nothing happens, i preferably want to be able to comunicate using flash.

can anybody help me with getting started? i need it pretty much spelled out :(
Satchmo Prototype
eSheep
Join date: 26 Aug 2004
Posts: 1,323
08-02-2005 08:13
I'm not sure what your trying to do, and a little more info would help... however, I'll post my first ever XML-RPC project when I was just tooling around trying to figure out how it worked. Don't mind any ugliness...

It was a perl script located on an offworld server, that could move a tank remotely. The tank's Key is hardcoded in, but the location and distance values are specified as standard in.

#########
# Perl Code #
#########

#!/usr/bin/perl
use strict;

require RPC::XML;
require RPC::XML::Client;

#HardCoded Key Value Here#
my $key = "3a84fa99-e076-c8f4-2e6d-7e5040c19a86";
my $ival = $ARGV[0];
my $sval = $ARGV[1];

print "my first arg is $ARGV[0]\n" . "my second arg is $ARGV[1]\n";

my $client = RPC::XML::Client->new('http://xmlrpc.secondlife.com:80/cgi-bin/xmlrpc.cgic');

my $request = RPC::XML::request->new('llRemoteData', RPC::XML::struct->new(
'Channel' => RPC::XML::string->new($key),
'IntValue' => RPC::XML::int->new($ival),
'StringValue' => RPC::XML::string->new($sval)
)
);

my $response = $client->simple_request($request);
if (!$response) {
print $RPC::XML::ERROR, "\n";
} else {
print $response->{StringValue}, "\n";
print $response->{IntValue}, "\n";
}

###############
#LSL residing in Tank #
###############

// XML-RPC example

key gChannel; // my llRemoteData channel

DEBUG(list out) { // output debug info
llSay(0, llList2CSV(out));
}

default { // initialize XML-RPC
state_entry() {
llOpenRemoteDataChannel(); // create an XML-RPC channel
// this will raise remote_data event REMOTE_DATA_CHANNEL when created
}

remote_data(integer type, key channel, key message_id, string sender, integer ival, string sval) {
if (type == REMOTE_DATA_CHANNEL) { // channel created
DEBUG(["Channel opened", "REMOTE_DATA_CHANNEL", channel, message_id, sender, ival, sval]);
gChannel = channel;
llSay(0, "Ready to receive requests on channel \"" + (string)channel +"\"";);
state go; // start handling requests
} else DEBUG(["Unexpected event type", type, channel, message_id, sender, ival, sval]);
}
}

state go { // handle requests
remote_data(integer type, key channel, key message_id, string sender, integer ival, string sval) {
if (type == REMOTE_DATA_REQUEST) { // handle requests sent to us
//DEBUG(["Request received", "REMOTE_DATA_REQUEST", channel, message_id, sender, ival, sval]);
// handle request
//llSay(0, "The real world has called to say: "+ sval);
if (sval == "Right";)
{
llSay(0, "Remote Instruction to Move " + (string)ival + " places Right.";);
llSetPos(llGetPos() + <0, ival, 0.0>;);
llRemoteDataReply(channel,message_id, "Moving Forward",1);
}
else if (sval == "Left";)
{
llSay(0, "Remote Instruction to Move " + (string)ival + " places Left.";);
llSetPos(llGetPos() + <0, -(ival), 0.0>;);
llRemoteDataReply(channel,message_id, "Moving Back",1);
}
else if (sval == "Up";)
{
llSay(0, "Remote Instruction to Move " + (string)ival + " places Up.";);
llSetPos(llGetPos() + <0, 0, ival>;);
llRemoteDataReply(channel,message_id, "Moving Left",1);
}
else if (sval == "Down";)
{
llSay(0, "Remote Instruction to Move " + (string)ival + " places Down.";);
llSetPos(llGetPos() + <0, 0, -(ival)>;);
llRemoteDataReply(channel,message_id, "Moving Down",1);
}
else if (sval == "Back";)
{
llSay(0, "Remote Instruction to Move " + (string)ival + " places Back.";);
llSetPos(llGetPos() + <ival, 0, 0>;);
llRemoteDataReply(channel,message_id, "Moving Back",1);
}
else if (sval == "Forward";)
{
llSay(0, "Remote Instruction to Move " + (string)ival + " places Forward.";);
llSetPos(llGetPos() + <;-(ival), 0, 0>;);
llRemoteDataReply(channel,message_id, "Moving Forward",1);
}
else { // IMPORTANT: a reply MUST always be sent
llRemoteDataReply(channel, message_id, "", 0);
}
} else DEBUG(["Unexpected event type:", type, channel, message_id, sender, ival, sval]);
}

state_exit() {
llCloseRemoteDataChannel(gChannel); // clean up when you no longer want to handle requests
}
}
_____________________

----------------------------------------------------------------------------------------------------------------
The Electric Sheep Company
Satchmo Blogs: The Daily Graze
Satchmo del.icio.us
Zarf Vantongerloo
Obscure Resident
Join date: 22 Jun 2005
Posts: 110
08-02-2005 08:21
There is an extended PHP sample for XML-RPC in the LSL wiki:

http://secondlife.com/badgeo/wakka.php?wakka=ExampleRPC2PHP

This sample includes the code to e-mail the newly opened data channel to the remote server.
Pru Costello
Not My President
Join date: 5 Jun 2005
Posts: 25
08-02-2005 09:09
thanks for the replies, but one of my main problems is that i don't know how to use the PHP or Perl as it's just code and i don't know how to input data into it or how to retrive it from that code.
Satchmo Prototype
eSheep
Join date: 26 Aug 2004
Posts: 1,323
08-02-2005 09:24
The serverside XML-RPC can be written in a variety of languages.... if you don't know any of those languages your gonna find it near impossible to do XML-RPC stuff.

I would suggest getting a Learning Perl or Learning PHP book from O'Reilly and Associates if your interested in learning one of those scripting languages.

How else can we help you? What exaclty are you looking for/tryng to do?
_____________________

----------------------------------------------------------------------------------------------------------------
The Electric Sheep Company
Satchmo Blogs: The Daily Graze
Satchmo del.icio.us
Pru Costello
Not My President
Join date: 5 Jun 2005
Posts: 25
08-02-2005 09:33
well if i was gonna make a tutorial on how to do this (and i will when i understand how to do it) i would make a teach ppl how to make a flash page that you can comunicate to and from the game with. i just need to know someway to input/ouput the information
Satchmo Prototype
eSheep
Join date: 26 Aug 2004
Posts: 1,323
08-02-2005 10:10
I don't know Flash but I can offer some basic design help maybe.

Most people communicate out of SL via llEmail... if you want to use XML-RPC to communicate with SL, most of the time you first send an llEmail to a server that contains the key of the object you want to communicate with . You need to have an objects Key to communicate via XMLRPC.

Then since there is no true outgoing XML-RPC connection, you need to send an XMLRPC message to the object and then just grab the objects reply. To rephrase that, all XML-RPC messeges you send to an object expect a reply.

To communicate from server to inworld object you need to send an XML-RPC packet to http://xmlrpc.secondlife.com/cgi-bin/xmlrpc.cgi. The packet should look like the one found on the Wiki, and the <name>Channel</name> is proceeded by <value><string>4a250e12-c02e-94fb-6d2f-13529cbaad63</string></value> Where that long string is your key.

When this properly crafted packet makes its way to the inworld object, the inworld object can then reply.

In my above code
llRemoteDataReply(channel,message_id, "Moving Forward",1);

This sends back the string "Moving Forward" and the integer 1.

So you could poll and object, by constantly sending request packets to it, and using the objects reply.

----------------------

So with all the being said.. your offworld program's input can either come from llEmail or from an XML-RPC polling cycle...

And your output is a properly crafted XML-RPC packet sent back to an object inside of SL.

Google shows lots of results for "XMLRPC Flash"

I'd just grab one of those flash xmlrpc libraries and go from there.
_____________________

----------------------------------------------------------------------------------------------------------------
The Electric Sheep Company
Satchmo Blogs: The Daily Graze
Satchmo del.icio.us
nonnux white
NN Dez!gns
Join date: 8 Oct 2004
Posts: 90
08-02-2005 18:00
the page u show from google is not very good, for working with SL

i tested it and is not working. i posted here about flash and SL, i am still developping this protocol, IM me in world...
_____________________
Alondria LeFay
Registered User
Join date: 2 May 2003
Posts: 725
08-02-2005 19:44
Here is a working (tested) XML-RPC implementation using Action Script 1.0

Requires xml-rpc.as from above mentioned site

CODE

// Flash ActionScript 1.0 SL XML-RPC Example
// By Alondria LeFay
#include "xml-rpc.as"

objXMLRPC = new XMLRPC("http://xmlrpc.secondlife.com:80/cgi-bin/xmlrpc.cgi",30);
objLogin = new XMLRPC_Object("struct");

objLogin.AddMember("Channel","00000000-0000-0000-0000-000000000000","string");
objLogin.AddMember("IntValue",100,"int");
objLogin.AddMember("StringValue","Hello from Flash!","string");
objXMLRPC.AddParameter(objLogin);
objXMLRPC.Call("llRemoteData");

// Event based method
objXMLRPC.onLoaded = function ()
{
trace("Transmit successfull.");
// do the objResults = objXMLRPC.GetResults(); stuff in here ...
}
objXMLRPC.onFailed = function (why)
{
trace("Transmit failed. Error: "+why);
}
Pru Costello
Not My President
Join date: 5 Jun 2005
Posts: 25
08-03-2005 15:50
yay, that works! i can send messages to SL :D

but... how do i get it from SL?