HtmlPortal.borg

HtmlPortal.borg


{
HTMLPORT: 8080;
MAXSOCKETS: 100;

serversocket:0;

request:0;

HTML_INIT()::
{
    serversocket:=socket();
      if(serversocket < 0, display("Error making serversocket" + eoln));
    err:socket_bind(serversocket, HTMLPORT);
        if(err = -1, display("Error binding serversocket to port" + eoln));
    err:=socket_listen(serversocket, MAXSOCKETS);
    if(err = -1, display("Error listening to serversocket port" + eoln))

};

HTML_CONTINUE()::
{
    clientsocket:socket_accept(serversocket);

    if(clientsocket > 0,
    {
        request:=request +1;
        webreq:new("webreq" + text(request), load("examples/WebServer/WebRequest.borg"));
        txt:socket_receive(clientsocket);
        while(length(txt) = 0,txt:=socket_receive(clientsocket));
        while(length(txt) > 0,
        {
            if(substr(txt, 1, 4) = "GET ",
            {
                req:substr(txt, 5, length(txt));
                space: strstr(req, " ");
                req:substr(req, 1, space);
                webreq->handlehtmlrequestwithsocket(clientsocket,req)
            },
            display("Html weird request" + text(txt) + eoln));
            txt:=socket_receive(clientsocket)
        })
    })
};

main()::
{
    new("webdispatcher", load("examples/WebServer/WebDispatcher.borg"));
    HTML_INIT();
    while(request < MAXSOCKETS, HTML_CONTINUE())
};

main()
}