Second Life web service with rails (1/2)
By jul on Wednesday, July 11 2007, 20:27 - Permalink
In this first part, we will see how to communicate with an in-world object from a ruby on rails application thanks to XML-RPC. At the beginning, we define a second life structure (app/models/second_life_struct.rb) which represent the API format of second life :
class SecondLifeStruct < ActionWebService::Struct member "Channel", :string member "StringValue", :string member "IntValue", :int end
Next, we create a new rails API (app/apis/second_life_api.rb) which use the structure :
class SecondLifeApi < ActionWebService::API::Base inflect_names false api_method "llRemoteData", :expects=>[SecondLifeStruct], :returns=>[SecondLifeStruct] end
Before continuing, let's see the object LSL script which receive communication :
default
{
state_entry()
{
llOpenRemoteDataChannel();
}
remote_data(integer type, key channel, key message_id, string sender, integer ival, string sval)
{
if(type==REMOTE_DATA_CHANNEL) {
llOwnerSay("Communication channel: "+(string)channel);
}
if(type==REMOTE_DATA_REQUEST) {
llOwnerSay(sval);
llRemoteDataReply(channel,message_id,"Everything is alright",0);
}
}
}
Communication channel is an unique key which permit to communicate back with this object from the Linden's webservice. We must copy this key for loading our rails web page (/second_life/test_object?channel=key)
We just have to define the controller now:
class SecondLifeController < ApplicationController
web_client_api :second_life, :xmlrpc, "http://xmlrpc.secondlife.com/cgi-bin/xmlrpc.cgi", :timeout=>90
def test_object
canal=params[:channel]
begin
resultat=second_life.llRemoteData(SecondLifeStruct.new("Channel"=>canal,"StringValue"=>"Hello World!","IntValue"=>"0"))
render :text=>resultat["StringValue"]
rescue
render :text=>"Object doesn't respond"
end
end
end
That's all! When we load the page, second life object says "Hello World!" In the next post, we will see how to communicate in the other way : from in-world object to rails application.
More informations about second life XML-RPC format here.
Comments
Following my exploration, millions of persons in the world receive the credit loans from good creditors. Thence, there is great possibilities to find a bank loan in every country.
http://www.coach-bags-outlet.com/ coach bags outlet
http://www.coach-bags-outlet.com/ coach bags
http://www.coach-bags-outlet.com/co... Coach Baby Bags
http://www.coach-bags-outlet.com/co... Coach Backpack Bags
http://www.coach-bags-outlet.com/co... Coach Claire Bags
http://www.coach-bags-outlet.com/co... Coach Garnet Bags
http://www.coach-bags-outlet.com/co... Coach HOBO Bags
http://www.coach-bags-outlet.com/co... Coach Luggage Bags
http://www.coach-bags-outlet.com/co... Coach Patchwork Purse
http://www.coach-bags-outlet.com/co... Coach Shoulder Bags
http://www.coach-bags-outlet.com/co... Coach Spotlight Bags
http://www.coach-bags-outlet.com/co... Coach Travel Bags
http://www.coach-bags-outlet.com/co... New Coach Handbags
http://www.coach-bags-outlet.com/co... COACH JEWELRY
http://www.coach-bags-outlet.com/co... Coach Earrings
http://www.coach-bags-outlet.com/co... COACH WALLETS
http://www.coach-bags-outlet.com/co... COACH SHOES
http://www.coach-bags-outlet.com/co... Coach Heels
http://www.coach-bags-outlet.com/co... Coach Sandals
http://www.coach-bags-outlet.com/co...
http://www.chanelbags2010.com/ chanel bags 2010
http://www.chanelbags2010.com/ chanel bags
http://www.chanelbags2010.com/ chanel bags online
http://www.chanelbags2010.com/chane... Chanel Luggage
http://www.chanelbags2010.com/chane... Chanel Cambon Bags
http://www.chanelbags2010.com/chane... New Chanel Handbags
http://www.chanelbags2010.com/chane... Chanel Tote Bags
http://www.chanelbags2010.com/chane... Chanel Wallets
http://www.chanelbags2010.com/chane... Chanel Belts
http://www.chanelbags2010.com/chane... Chanel Bracelets
http://www.chanelbags2010.com/chane... Chanel Earrings
http://www.chanelbags2010.com/chane... Chanel Jewelry
http://www.chanelbags2010.com/chane... Chanel Rings
http://www.chanelbags2010.com/chane... Chanel Sunglasses
Dont stop believing. Hold on to that feeling.
Welcome to visit our store, <a href="http://www.UGGaustraliabootsonline....">shopping for UGG boots</a>. We offer diverse styles,for example, <a href="http://www.UGGaustraliabootsonline....">UGG classic cardy boots</a>, <a href="http://www.UGGaustraliabootsonline....">UGG boots usa</a>, <a href="http://www.UGGaustraliabootsonline....">UGG cardy boots</a>, <a href="http://www.UGGaustraliabootsonline....">UGG bailey button boots</a><a href="http://www.UGGaustraliabootsonline....">UGG bailey boots</a> and <a href="http://www.UGGaustraliabootsonline....">UGG argyle boots</a>. And now we have <a href="http://www.UGGaustraliabootsonline....">cheap classic tall UGG boots 5815 mulberry</a> and <a href="http://www.UGGaustraliabootsonline....">UGG cardy boots on sale</a>. Of course, you can <a href="http://www.UGGaustraliabootsonline....">buy discount UGGs</a> at the end of season. For more information, we have <a href="http://www.UGGaustraliabootsonline....">UGG boots classic tall black</a>, <a href="http://www.UGGaustraliabootsonline....">UGG boots classic tall chestnut</a>, <a href="http://www.UGGaustraliabootsonline....">UGG boots classic tall chocolate</a>, <a href="http://www.UGGaustraliabootsonline....">UGG boots classic tall grey</a>, <a href="http://www.UGGaustraliabootsonline....">UGG boots classic tall pink</a> and <a href="http://www.UGGaustraliabootsonline....">UGG boots classic tall sand</a>, for short classic UGG boots, we have <a href="http://www.UGGaustraliabootsonline....">UGG boots classic short black</a>,<a href="http://www.UGGaustraliabootsonline....">UGG boots classic short chestnut</a>, <a href="http://www.UGGaustraliabootsonline....">UGG boots classic short chocolate</a>, <a href="http://www.UGGaustraliabootsonline....">UGG boots classic short grey</a> and <a href="http://www.UGGaustraliabootsonline....">UGG boots classic short sand</a>. It is worth mentioning that coach handbags are alse broght to our store to make a big market position. we all know that <a href="http://www.fashioncoachhandbag.com/">fashion coach handbags</a> are popular in the world, so you can have a detail look on our new products. At the same time i introduce several new styles to you, <a href="http://www.fashioncoachhandbag.com/... <a href="http://www.fashioncoachhandbag.com/...">Coach Hamptons Signature Handbags</a> , <a href="http://www.fashioncoachhandbag.com/...">light blue leather embossed coach handbag</a>, <a href="http://www.UGGaustraliabootsonline....">UGG bailey button triplet black</a>, <a href="http://www.UGGaustraliabootsonline....">UGG bailey button triplet chestnut</a>, <a href="http://www.UGGaustraliabootsonline....">UGG bailey button triplet chocolate</a>, <a href="http://www.UGGaustraliabootsonline....">UGG bailey button triplet grey</a>, <a href="http://www.UGGaustraliabootsonline....">UGG bailey button triplet sand</a> <a href="http://www.fashioncoachhandbag.com/...">Coach Addison Patent Multifunction Cream Bag</a> and <a href="http://www.fashioncoachhandbag.com/...">Coach Addison Patent Multifunction Grey Bag</a>. they are all hot selling ones at this season. If you prefer the others, dont worry, we also can offer you, for example, <a href="http://www.fashioncoachhandbag.com/...">coach opt art sabrina</a>, <a href="http://www.fashioncoachhandbag.com/...">coach optic leah</a>, <a href="http://www.fashioncoachhandbag.com/...">Coach Alex Signature Patent Leather Black Handbag</a>, <a href="http://www.fashioncoachhandbag.com/...">Coach Alex Signature Sateen Brown Bag</a>, <a href="http://www.fashioncoachhandbag.com/...">Coach Alex Signature Sateen Purple Bag</a>, <a href="http://www.fashioncoachhandbag.com/...">Coach Alex Zebra Charm Leather Handbag</a>, <a href="http://www.fashioncoachhandbag.com/...">Coach Audrey Op Art Black Tote Handbag</a>, <a href="http://www.fashioncoachhandbag.com/...">Coach Black Signature Backpacks Bag</a> and <a href="http://www.fashioncoachhandbag.com/...">coach sabrina brown</a>. So its a nice choose for you to select the one you like in our store. Welcome!
Big brother final tonight!
This post's comments feed