Controlling an object from a web page
|
|
SuezanneC Baskerville
Forums Rock!
Join date: 22 Dec 2003
Posts: 14,229
|
11-04-2006 21:25
I'd like to be able to have a web page with some textboxes which would allow a person to type in some values which would get sent to an object in SL.
An example would be a page with some fields to enter the values that control a particle system's behavior.
I don't have some particular application in mind, just wondering about ways to overcome SL lack of basic input functions like dialog boxes with labeled editboxes, sliders, etc., over than complex multiprim objects that somewhat tortorously emulate the function of simple dialog boxes.
I've read about llHttpRequest, llEmail, and the XML-RPC commands in the wiki. My free web host doesn't do email, so if someone happens to know a free web host that does php and has email that would be a help in fiddling with this stuff.
_____________________
-
So long to these forums, the vBulletin forums that used to be at forums.secondlife.com. I will miss them.
I can be found on the web by searching for "SuezanneC Baskerville", or go to
http://www.google.com/profiles/suezanne
-
http://lindenlab.tribe.net/ created on 11/19/03.
Members: Ben, Catherine, Colin, Cory, Dan, Doug, Jim, Philip, Phoenix, Richard, Robin, and Ryan
-
|
|
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
|
11-04-2006 21:38
From: SuezanneC Baskerville I'd like to be able to have a web page with some textboxes which would allow a person to type in some values which would get sent to an object in SL. An example would be a page with some fields to enter the values that control a particle system's behavior. I don't have some particular application in mind, just wondering about ways to overcome SL lack of basic input functions like dialog boxes with labeled editboxes, sliders, etc., over than complex multiprim objects that somewhat tortorously emulate the function of simple dialog boxes. I've read about llHttpRequest, llEmail, and the XML-RPC commands in the wiki. My free web host doesn't do email, so if someone happens to know a free web host that does php and has email that would be a help in fiddling with this stuff. I looked and looked for such a freebie service - problem is you can't fine one that allows outbound connections (which you need for XML-RPC) becasue they get abused - spam stuff and DDOS attacks. I went ahead and buckled under and payed for a site. (Wasn't that expensive.) BTW, there's a nice PHP library for easy XML-RPC here.
|
|
SuezanneC Baskerville
Forums Rock!
Join date: 22 Dec 2003
Posts: 14,229
|
11-04-2006 22:36
Thanks for the comment about the absence of free email along with free web hosting. I have been looking at free and paid hosts for a while but had only been looking at free hosts for basic webspace and which languages they support. Not email. Also for the comment about outbound connections, I don't know enough about this stuff to have thought to be looking for that. I saw a site or two earlier tonight that might serve a LSL-External Reality experimenter's purposes for just two bucks a month, which aint far from free. I've heard mostly good things about BlueHost up till lately, the exeeeded CPU quota problem and other problems caused by more customers than their hardware wants to handle have produced many comments in the past months. As with many purchases, it's not just the outflow of money that causes delay, it's the fear that you aren't getting the best deal you could or getting the one you really ought to. Bluehost would server the purpose, I take it, and allow those so inclined to fiddle with the stuff in the Fantastico package, a bunch of free stuff like a Wordpress blog and such that are supposedly made to be very easy to install. So if you got a package like that and enjoy fiddling on the computer but don't want to sprain your brain too much the small monthly fee might yield a good bit of pleasant timepassing other than in it's utility for SL. Be that as it may, here's some code from the wiki: http://lslwiki.com/lslwiki/wakka.php?wakka=XMLRPCImplementations<?php function llRemoteData($channel, $intvalue, $stringvalue) { $host = "xmlrpc.secondlife.com"; $port = 80; $uri = "/cgi-bin/xmlrpc.cgi"; $request = xmlrpc_encode_request('llRemoteData', array( 'Channel' => $channel, 'IntValue' => $intvalue, 'StringValue' => $stringvalue)); $fp = fsockopen($host, $port, $errno, $errstr); $query = "POST " . $uri . " HTTP/1.0\n" . "User_Agent: PHP XML-RPC Interface\n" . "Host: " . $host . "\n" . "Content-Type: text/xml\n" . "Content-Length: " . strlen($request) . "\n\n" . $request . "\n"; if (!fputs($fp, $query, strlen($query))) return NULL; // some sort of write error occured $xmlresp = ""; //I replaced some code that was here but did not work. This should work just as well, in less code and quicker ;p //read the maximum amount (if you have more bytes than 8192, this method will not work) $response = fread($fp, 8192); //grab the XML $xmlresp = (substr($response, strpos($response, "\r\n\r\n")+4)); fclose($fp); if ($xmlresp == "") return NULL; else return xmlrpc_decode($xmlresp); } ?> The wiki presents these examples but says nothing on the page where they are to help a novice know exactly what to do with them. I assume that one puts this file into the place in their server whre php code goes. What else does one have to do to make this code serve it's purpose? Same question for LSL Example: , Example Request , and Example Response
_____________________
-
So long to these forums, the vBulletin forums that used to be at forums.secondlife.com. I will miss them.
I can be found on the web by searching for "SuezanneC Baskerville", or go to
http://www.google.com/profiles/suezanne
-
http://lindenlab.tribe.net/ created on 11/19/03.
Members: Ben, Catherine, Colin, Cory, Dan, Doug, Jim, Philip, Phoenix, Richard, Robin, and Ryan
-
|
|
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
|
11-04-2006 23:12
Lessee... First you load up the LSL example... or whatever XML-RPC script. The first thing the script does is regiser itself and get a "channel". This is just a unique identifier that allows them to use the generic URL. You take that "channel" and plug it into your PHP code... assuming the above is in place, your "main" would call it thus: <?php
$return = llRemoteData("some00kind00of-00uniq-id00", 0, "How are you?");
print_r($return);
?> Which should return something like: $return => { String = "Fine, thanks!" Integer = 1 } to the browser calling the PHP script becasue that's what the example LSL script returns if you send it "How are you?" That example response is in "raw" form, the PHP script in the example "decodes" the response into an array for easy use.
|
|
SuezanneC Baskerville
Forums Rock!
Join date: 22 Dec 2003
Posts: 14,229
|
11-04-2006 23:49
Ok, I'm doing what I think is meant by loading the LSL example, which is just rezzing a box and naming it something better than object and pasting in the LSL example script, which is: // 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 if (sval == "How are you?") { // we do something special on that string parameter // send a reply to this request, referencing the senders message id llRemoteDataReply(channel, message_id, "Fine, thanks!", 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 } }
It compiled and saved properly, but I have already screwed up - I didn't rename the box to something sensible BEFORE I started scripting, which for a person as easily distracted as me is most certainly the time to do that. When you said "the above is in place" did you mean the LSL example, which is an LSL script that goes in an object, or the above XML-RPC implementation in PHP? What name should I give the XML-RPC implemention file? Is there something in one of the other files that assumes I know what the name of the XML-RPC file is? For the time being I am saving it as XMLRPCimplementation.php . This may a just a learning experience, freehostia. my current host, may well not allow outbound communication. -------- Ok, I now have the scripted object with LSL example in it, and the XMLRPCimplementation file saved. I suspect I am misinterpreting things completely. You say "my main", what main? So I am now saving a file called "MyMain.php" with just <?php
$return = llRemoteData("some00kind00of-00uniq-id00", 0, "How are you?");
print_r($return);
?>
in it.
_____________________
-
So long to these forums, the vBulletin forums that used to be at forums.secondlife.com. I will miss them.
I can be found on the web by searching for "SuezanneC Baskerville", or go to
http://www.google.com/profiles/suezanne
-
http://lindenlab.tribe.net/ created on 11/19/03.
Members: Ben, Catherine, Colin, Cory, Dan, Doug, Jim, Philip, Phoenix, Richard, Robin, and Ryan
-
|
|
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
|
11-05-2006 02:25
Me & my jargon  Ok - yes, by "load up" I do mean insert the LSL example as a script in a prim. When you save it in the prim, it should say the channel ID that was reserved for it. Your PHP page should look like so: <?php
function llRemoteData($channel, $intvalue, $stringvalue) { $host = "xmlrpc.secondlife.com"; $port = 80; $uri = "/cgi-bin/xmlrpc.cgi"; $request = xmlrpc_encode_request('llRemoteData', array( 'Channel' => $channel, 'IntValue' => $intvalue, 'StringValue' => $stringvalue)); $fp = fsockopen($host, $port, $errno, $errstr); $query = "POST " . $uri . " HTTP/1.0\n" . "User_Agent: PHP XML-RPC Interface\n" . "Host: " . $host . "\n" . "Content-Type: text/xml\n" . "Content-Length: " . strlen($request) . "\n\n" . $request . "\n";
if (!fputs($fp, $query, strlen($query))) return NULL; // some sort of write error occured
$xmlresp = "";
//I replaced some code that was here but did not work. This should work just as well, in less code and quicker ;p //read the maximum amount (if you have more bytes than 8192, this method will not work) $response = fread($fp, 8192); //grab the XML $xmlresp = (substr($response, strpos($response, "\r\n\r\n")+4));
fclose($fp); if ($xmlresp == "") return NULL; else return xmlrpc_decode($xmlresp); }
/*
Main program:
*/
$return = llRemoteData("some00kind00of-00uniq-id00", 0, "How are you?");
print_r($return);
?> Replace "some00kind00of-00uniq-id00" with the key the LSL script mentioned was it's chanel. Save it as, for instance, "testxmlrpc.php" in your web server's "root" directory (the directory where it finds files to serve.) in your web browser, type in http://<your URL>/testxmlrpc.php You should see the response from the LSL script in your browser.
|