Writing web servers

8 views
Skip to first unread message

Phil Rhodes

unread,
Dec 26, 2009, 2:13:29 AM12/26/09
to jsl...@googlegroups.com
Hi,
 
I'm a little confused as to how one would use the Socket object to write something like a simple web server (just as an example). There don't seem to be any event-style callbacks available from which one could trigger code to handle a connection event.
 
Do we just poll? Can we do this asynchronously? How do I get jslibs to wait around in a non-blocking state until something happens?
 
My baseline for this sort of thing is using the Winsock activeX control under windows script host, which is an event-capable COM control. Can I make jslibs behave in a similar way?
 
Am I approaching this all in completely the wrong way?
 
P

soubok

unread,
Dec 26, 2009, 6:20:23 AM12/26/09
to jsl...@googlegroups.com
Hi,

jslibs use a tiny HTTP server to manage network exchange for the XUL debugger.
The source code is:
http://code.google.com/p/jslibs/source/browse/trunk/src/jsdebug/debugger.js#55
There is another (much more complex) HTTP server used by jsircbot:
http://code.google.com/p/jsircbot/source/browse/trunk/httpServer.jsmod

There is no event loop in jslibs, you have to manage I/O events
through the Poll function.

In the following example, socket1.readable() is called if a network
event has been received.
The socket1.readable function is internally called by the Poll function.
Poll may call writable, readable, hangup, exception and error function
for each socket from the descriptor array (1st argument).

socket1.readable = function(soc) { Print( soc.Recv(); ) }
var count = Poll( [socket1, socket2, ...], 1000 );

You can also find many examples with Poll() in the QA tests file:
http://jslibs.googlecode.com/svn/trunk/src/jsio/jsio_qa.js

Franck.

PS. tell me if you need more explanations.

> --
> Group jslibs - http://groups.google.com/group/jslibs -
> jsl...@googlegroups.com
> Unsubscribe: jslibs-un...@googlegroups.com

Phil Rhodes

unread,
Dec 29, 2009, 5:26:55 AM12/29/09
to jsl...@googlegroups.com
Could jscrypt be used to implement SSL on a simple JSlibs-based HTTP server?

P


--------------------------------------------------------------------------------

No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 8.5.430 / Virus Database: 270.14.119/2586 - Release Date: 12/25/09
09:33:00

soubok

unread,
Dec 29, 2009, 6:17:49 AM12/29/09
to jsl...@googlegroups.com
jscrypt provides all required tools to make SLL, but I don't knkow how
hard it is to do it.
BTW, dropbear (http://matt.ucc.asn.au/dropbear/dropbear.html) is a SSH
server and client based on LibTomCrypt (like jscrypt).

Franck.

Reply all
Reply to author
Forward
0 new messages