Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Second Life: Talking to the outside world.

Options
  • 20-03-2007 10:54pm
    #1
    Registered Users Posts: 21,264 ✭✭✭✭


    thought I'd document this here as I am finding it a pain to get information and I need somewhere to stick stuff I can find again. :)

    Anyway, if your not familar with SL -> www.secondlife.com

    They allow you to develop stuff in LSL code. The code is reasonable enough, but still trying to figure stuff out. If there is any SL experts out there let me know. :)

    So I wanted to create an object in SL that would talk to a servlet and then respond back.

    I created a basic servlet with the following doPost.

    [PHP]
    File file = new File("/SLHeaders.txt");

    PrintWriter out = new PrintWriter(file);

    out.println("**** SLTalkTo Begin ****");
    out.println("Request headers:");

    Enumeration headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
    String key = (String)headerNames.nextElement();
    String value = request.getHeader(key);
    out.println(" " + key + " = " + value);
    }

    out.println("**** SLTalkTo End ****");

    out.close();

    response.setContentType("text/plain");
    PrintWriter body = response.getWriter();
    body.println("Hello from the servlet!");
    body.close();
    [/PHP]

    Simple enough servlet. It would save the HTTP headers to a file and tell the SL object Hello.

    So in SL I then selected build, created a generic sphere and added the following script.

    [PHP]
    key http_request_id;
    default
    {

    touch_start(integer total_number)
    {
    string url = "http://my.server.com/SLTest/SLTalkTo";
    list parameters = [HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"];

    string body = "";

    http_request_id = llHTTPRequest(url, parameters, body);
    }

    http_response(key request_id, integer status, list metadata, string body)
    {
    llSay(0,body);
    }
    }
    [/PHP]

    For obvious reasons I removed my test server name. But this appears to work fine. When I ran it I got the following in the text file.
    **** SLTalkTo Begin ****
    Request headers:
    host = my.server.com
    pragma = no-cache
    accept-encoding = deflate, gzip
    accept = text/*
    accept-charset = utf-8;q=1.0, *;q=0.5
    content-type = application/x-www-form-urlencoded
    user-agent = Second Life LSL/1.13.4(8) (http://secondlife.com)
    x-secondlife-shard = Production
    x-secondlife-object-name = SLTalkToTest
    x-secondlife-object-key = 6959247c-b3fd-dfc5-5aa0-a88422839040
    x-secondlife-region = Sandbox Island (254464, 255488)
    x-secondlife-local-position = (160.549347, 244.315796, 26.307798)
    x-secondlife-local-rotation = (0.000000, 0.707107, 0.000000, 0.707107)
    x-secondlife-local-velocity = (0.000000, 0.000000, 0.000000)
    x-secondlife-owner-name = xxxxxxxx
    x-secondlife-owner-key = e7c80d7d-aabd-4e6f-86ee-43520181812d
    content-length = 25
    via = 1.1 sim2445.agni.lindenlab.com:3128 (squid/2.5.STABLE9)
    x-forwarded-for = 127.0.0.1
    cache-control = max-age=259200
    connection = keep-alive
    **** SLTalkTo End ****

    So now my next steps is to figure out how to pass data like attributes/parameters and return the same to the object so it can interact on it.


Comments

  • Closed Accounts Posts: 132 ✭✭Hells_Belle


    Ahh the joys of LSL :)

    Actually, the folks in the scripting forum on the secondlife website are very nice people, especially when you're asking more interesting questions than "how do I hand out a notecard?"

    Which is, err, about the level of question I normally ask :)


Advertisement