About this sample
This sample implements a very simple WEB server. It uses the
NetStream library is written for Windows Scripting Host (there is
also version for newObjects Microhost).
It serves only the resources in the script's directory and only
a few file types. If you want you can change the source code and
add more functionality. The HTTP support is minimal just enough to
get it working.
The sample uses blocking sockets and serves the requests
sequentially. Therefore the resources should be small in order to
avoid long timeouts. Thus a WEB server implemented this way is
good only for local usage by no more than 3-4 clients.
How to implement something better? For that purpose you will
need to use sockets in non-blocking mode, check their state from
time to time and send little chunks of data through every
connection that must be served. It will be even better to start
some threads and serve more than one request at a time. Using both
ActiveX Pack1 and the NetStreams this can be done in various ways
and will not need too much code to be written.
See source code (right-click and choose Save As):
VBScript
JScript
How to run the sample?
WSH: Make sure you have Windows Script Host installed. Open a
command prompt window. Change the current directory to the
sample's directory and type:
cscript http-srv.vbs 0.0.0.0 10
You can type another port or specify particular interface on
your machine.
Microhost: Open newObjects MicroHost (from Start Menu ->
Programs -> newObjects -> newObjects ActiveX Pack1 or
alternatively open the run prompt and type nwmicrohost.exe).
Choose run from the menu and browse to the sample directory (MicroHost
version - not WSH version). Change to VBScript and open the http-srv.vbs.
Then you will be asked to specify the address and the port on
which the server will listen.
After starting it open a browser and go to the address and port
specified (if 0.0.0.0 has been used choose any of your machine's
interfaces or just use localhost if you are browsing from the same
machine). |