I also used a long poll technique to integrate a webpage user interface for water-resource usage game work I did with
Intel and Sandia National Labs a while back. This made the webpage long pull for updates from OpenSimulator so that
actions done by a player in-world (such as clicking on a water-using crop) would be received by javascript on the
webpage and acted on appropriately (in this case by changing the webpage tab to the crop information page). This was to
get around the limitations of in-world user interfaces (MOAP on a hud wasn't working back then).
The code is at [1] if an example would be useful. The polling is done by getUpdate() in [2] and the simulator sets up
and initially handles a webservice call at [3], using JSON as the data transport. When I get some spare time I'm going
to write some blog posts about its technical aspects.
I didn't find any issue with timeouts - I found that the javascript could poll
indefinitely.
[1] https://github.com/justincc/waterwars
[2]
https://github.com/justincc/waterwars/blob/master/web/waterwars/js/waterwars/waterwars.js
[3]
https://github.com/justincc/waterwars/blob/master/src/WaterWars/WebServices/ViewerWebServices.cs
On 15/09/12 10:53, Dahlia Trimble wrote:
I've had excellent luck serving many simultaneous long-poll requests with the
HTTP server that comes with OpenSimulator.
Bear in mind though that each active request may consume a thread so you might
need to increase available threads if you
see problems. I'm not certain if the request threads are managed by the
threadpool in OpenSimulator or if they are
direct calls into .NET framework. I did search through the code once and found
many threads that were not treadpool
managed but I can't remember if HTTP threads were or not.
On Fri, Sep 14, 2012 at 9:07 PM, Edmund Edgar <[email protected]
<mailto:[email protected]>> wrote:
I've got a situation with the money module I'm working on where I'd
like an external program (running on the client PC in parallel to the
viewer) to be able to be in almost constant contact with the server
while the user is logged in. (I want it to be able to find out
whenever the user wanted to buy something.)
I figure I can do this by having the external program long-poll the
OpenSim server. (The external program makes a request, the server
waits such time as it has something to tell the external program, then
responds. It gives up and responds if there's nothing to say after 30
seconds or so, at which point the external program will make a new
request and start the cycle again.)
At this point if I was serving a web application with Apache I'd start
worrying that I was hogging a bunch of threads and eating through the
memory. Is this the kind of thing I should be worrying about with
OpenSim, or can I merrily go ahead and long-poll without worrying?
The kind of thing I'm thinking of follows:
public void FirstRegionLoaded ()
MainServer.Instance.AddHTTPHandler ("/checkfortransactions/",
CheckForTransactions);
}
public Hashtable CheckForTransactions(Hashtable request) {
UUID userUUID = (get a user id using a session ID passed in the
request or something);
int i;
// poll for 30 seconds then give up
for (i=0; i<30; i++) {
if
(m_transactionsAwaitingNotification.containsKey("userUUID")) {
// Reply to the request
Hashtable reply = new Hashtable ();
reply["int_response_code"] = 200;
reply["str_response_string"] = "{ Some JSON goes here
}";
reply["content_type"] = "text/json";
return reply;
}
Thread.Sleep (1000);
}
Hashtable reply = new Hashtable ();
reply["int_response_code"] = 204; // No Content
return reply;
// The client will get this reply then hit /checkfortransactions/
again.
}
PS. Thanks for the replies to my C#-ignorant questions on previous threads.
--
Edmund Edgar
Avatar Classroom
Your classroom, on the web, in a virtual world.
[email protected] <mailto:[email protected]>
+81 090 3912 3380 <tel:%2B81%20090%203912%203380>
Skype: edmundedgar
Second Life: Edmund Earp
Linked In: edmundedgar
Twitter: @edmundedgar
http://www.avatarclassroom.com
_______________________________________________
Opensim-dev mailing list
[email protected] <mailto:[email protected]>
https://lists.berlios.de/mailman/listinfo/opensim-dev
_______________________________________________
Opensim-dev mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/opensim-dev
--
Justin Clark-Casey (justincc)
OSVW Consulting
http://justincc.org
http://twitter.com/justincc
_______________________________________________
Opensim-dev mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/opensim-dev