[MUD-Dev2] [DESIGN] AJAX Client/Servers?
Squid
jhvh at squid.org
Sun Feb 18 17:24:40 CET 2007
On 2/14 Philip wrote:
> Is anyone aware of or working on AJAX(ish) client/server code for
> something mud-like? I am specifically not interested in emulating
> a telnet+ansi connection in a browser. I am interested in the
> details of making http 1.1 keep-alive and chunking work (correctly?
> at all?) to minimize the amount of socket creation/teardown, error
> detection and recovery when sockets/connections close, etc. Extra
> points if the server end code is in python.
I've been interested in this topic for awhile, and thought I might share
some of my observations on the subject. I have been casually working on a
more traditional mud server written in Pike (a lpc derived scripting
language), but I plan on developing a web client for it.
One potential workaround to the lack of a constant connection is you can
use either a shockwave or java applet bridge to do a more traditional
socket connect to a mud server, and have that generate calls to
javascript. The upside is you can send live events to the client and have
a persistant state world without a database, the downside is the end user
still has to be able to connect to whichever port your mud is answering
on, which pretty much stops anyone from playing from a firewalled up
office, or computer lab still.
SocketJS:
http://dev.dschini.org/socketjs/
I have not gotten this library to work, but it started me down the path.
AFLAX:
http://www.aflax.org/examples/sockets/sockets.html
A much larger library designed for controlling flash via javascript, this
can be used to open a flash xmlsocket and be used as a bridge to
javascript events. I have gotten this working somewhat, however there are
some problems in the library, especially if you are trying to send words
such as <omg>, the flash bridge is trying to treat the content sent as
html.
The flash object has to be served from the mud server you are connecting
to, or you need to have another webserver on the mud with crossdomain.xml
(policy file) in the root to tell the socket it's okay to connect.
Another recommendation to anyone going down this path:
Instead of doing straight AJAX I recommend you look into JSON. Basically,
instead of sending raw xml, you send raw serialized javascript code. In
my case, Pike has a Public.Parser.JSON library (which requires json-c
installed). I can take a mapping structure such as ([ "msg" : "This is a
test.\n" ]), and then the javascript recieves it like:
{ \"msg\": \"This is a test.\n\" }
// this is part of the AFLAX library, but you can roll your own
var json = JSON.parse(str);
alert(json["msg"]);
The advantage to this is a eval is much faster than parsing xml.
Overall drawbacks:
-flash requires a crossdomain.xml policy file if you are connecting to a
different server
-flash socket requires that you send \0 as your 'end of line' terminator,
basically letting it know you're done with a packet.
-aflax/flash library gets crazy if you are sending tags that look like bad
html, such as <gossip>.
I had planned on writing my own java based gateway to get rid of some of
these problems, but then the wow expansion came out. ;)
-Joshua Hughes
More information about the mud-dev2-archive
mailing list