'how to turn you machine into a server
'run this program. You will then get a 
'message asking to allow permission 
'e.g., let this program past the firewall
'then start your webbrowser and enter
'loacalhost:3000 into the address line
'you will get the contents of the index.htm
'file that must be in the same folder
'as this exe. Extra stuff is printed
'for debugging

$TYPECHECK ON
$APPTYPE CONSOLE
$INCLUDE "RapidQ.INC"
$DEFINE DEBUG
$ESCAPECHARS ON

CONST filename$ = "index.html"

DIM HTTPServer AS QSocket, MasterSocket AS INTEGER
MasterSocket = HTTPServer.Open(3000)

DO
	IF HTTPServer.ConnectionReady(MasterSocket) <> False THEN
		DIM ClientSocket AS INTEGER, File AS QFILESTREAM

		ClientSocket = HTTPServer.Accept(MasterSocket)
		$IFDEF DEBUG
			PRINT ClientSocket
		$ENDIF
		IF File.Open(filename$, fmOpenRead) <> False THEN
			$IFDEF DEBUG
				PRINT "a"
			$ENDIF
			HTTPServer.WriteLine(ClientSocket, "HTTP/0.9 200 OK\r\n")
			WHILE File.EOF = False
				HTTPServer.WriteLine(ClientSocket, File.ReadLine + "\r\n")
			$IFDEF DEBUG
				PRINT "aa"
			$ENDIF
			WEND
			File.Close
			HTTPServer.Close(ClientSocket)
		ELSE
			HTTPServer.WriteLine(ClientSocket, "HTTP/0.9 404 Not found\r\n")
			$IFDEF DEBUG
				PRINT "b"
			$ENDIF
			HTTPServer.Close(ClientSocket)
		END IF
	END IF
LOOP
