View previous topic :: View next topic |
Author |
Message |
Shawn KiXforms Developer


Joined: 22 Feb 2003 Posts: 1983 Location: Canada
|
Posted: Mon Aug 30, 2004 3:19 pm Post subject: Build your own WebServer with Kixforms sockets. |
|
|
Just a posted an interim build - nothing major to report other than I am still working on GridView and Socket support. Wanted to experiment with easier methods of creating and using sockets, so built the ServerSocket object that will return a bound socket already in it's listening state ... works like this:
$ServerSocket = $System.ServerSocket(port)
Here's a very (very) fun little script ... its a home-brewed web-server... run it in the background uing WKIX32 like this:
c:\> wkix32 ws.kix
Then using any old browser (ie/mozilla tested) "browse" to your machine like this from the address bar:
Address: http://HOSTNAME
And bobs your uncle ... stirs the imagination. Here's the code:
This code requires the latest development build!
Code: |
break on
;
; WEB SERVER (LISTENER)
;
$ADDRESS = @WKSTA
$PORT = 7
$MAXCLIENTS = 5
$system = createobject("kixtart.system")
$form = $system.form()
$form.size = 400,300
$form.font = $system.font("verdana",10)
$form.text = "WebServer"
$form.location = 20,20
$statusbar = $form.statusbar()
$msgbox = $form.textbox()
$msgbox.multiline = "true"
$msgbox.dock = "fill"
$msgbox.text = ""
$msgbox.scrollbars = 2
$menu = $system.mainmenu()
$filemenu = $menu.menuitems.add("File")
$exitmenu = $filemenu.menuitems.add("Exit")
$exitmenu.onclick = "exitclick()"
$editmenu = $menu.menuitems.add("Edit")
$clearmenu = $editmenu.menuitems.add("Clear")
$clearmenu.onclick = "clearclick()"
$form.menu = $menu
$listener = $system.serversocket(80)
$listener.blocking = 0
$listener.onaccept = "accept($$system.eventobject)"
$sockets = $system.collection()
$form.show()
while $form.visible
$=execute($form.doevents)
loop
exit 1
function accept($socket)
$socket = $listener.accept()
$socket.blocking = 0
$socket.onreceive = "receive($$system.eventobject)"
$sockets.add($socket,$socket.handle)
$msgbox.appendtext("" + $socket.handle + " - " + $socket.remoteaddress + " accepted." + @CRLF)
endfunction
function receive($socket)
dim $resp, $string, $html
$string = $socket.receive()
$html = ""
$html = $html + "<HTML><HEAD><TITLE>@WKSTA</TITLE></HEAD>"
$html = $html + "<BODY>"
$html = $html + "<H3>Welcome to @WKSTA</H3><BR>"
$html = $html + "<TABLE BORDER=1 CELLPADDING=3 CELLSPACING=0 WIDTH=50%>"
$html = $html + "<TR><TH>Attribute</TH><TH>Value</TH></TR>"
$html = $html + "<TR><TD>Hostname</TD><TD>@WKSTA</TD></TR>"
$html = $html + "<TR><TD>Domain</TD><TD>@DOMAIN</TD></TR>"
$html = $html + "<TR><TD>Address</TD><TD>@IPADDRESS0</TD></TR>"
$html = $html + "<TR><TD>Operating System</TD><TD>@DOS</TD></TR>"
$html = $html + "<TR><TD>Product Suite</TD><TD>@PRODUCTSUITE</TD></TR>"
$html = $html + "<TR><TD>Product Type</TD><TD>@PRODUCTTYPE</TD></TR>"
$html = $html + "</TABLE>"
$html = $html + "</BODY></HTML>"
$resp = ""
$resp = $resp + "HTTP/1.0 200 OK" + @CRLF
$resp = $resp + "Content-type: text/html" + @CRLF
$resp = $resp + "Content-Length: " + LEN($html) + @CRLF + @CRLF
$resp = $resp + $html + @CRLF + @CRLF
$socket.send($resp)
$sockets.remove($socket.handle)
$msgbox.appendtext("" + $socket.handle + " - " + $socket.remoteaddress + " closed."+@CRLF)
$socket.close()
endfunction
|
-Shawn |
|
Back to top |
|
 |
Bonji KiXforms Aficionado


Joined: 10 Mar 2003 Posts: 393 Location: Virginia
|
Posted: Mon Aug 30, 2004 3:25 pm Post subject: |
|
|
Very nice Shawn!
This gets the little motor in my head spinning. _________________ -Ben |
|
Back to top |
|
 |
Jochen KiXforms Devotee


Joined: 05 Mar 2003 Posts: 1204 Location: Stuttgart, Germany
|
Posted: Mon Aug 30, 2004 3:29 pm Post subject: |
|
|
eh... neat ! _________________ Jochen
Tell me, and I will forget.
Show me, and I may remember.
Involve me, and I will understand. |
|
Back to top |
|
 |
Jochen KiXforms Devotee


Joined: 05 Mar 2003 Posts: 1204 Location: Stuttgart, Germany
|
Posted: Mon Aug 30, 2004 3:32 pm Post subject: |
|
|
hmmm...
you fergot to code exitclick() and clearclick() though.
Still the picture got through  _________________ Jochen
Tell me, and I will forget.
Show me, and I may remember.
Involve me, and I will understand. |
|
Back to top |
|
 |
Lonkero KiXforms Devotee


Joined: 13 Mar 2003 Posts: 1022 Location: Espoo, Finland
|
Posted: Mon Aug 30, 2004 8:50 pm Post subject: |
|
|
me just wonder, shouldn't this be in the game area?
I know, this can be made better than IIS5 but it still is far from real webserver... thus, it's just an game. _________________ Hammer |
|
Back to top |
|
 |
Shawn KiXforms Developer


Joined: 22 Feb 2003 Posts: 1983 Location: Canada
|
Posted: Mon Aug 30, 2004 9:22 pm Post subject: |
|
|
lol, your right dude - this is a real webserver ... in every sense of the term - just an extremely limited one with very little in the way of features ! :0)
actually believe it or not - one could write a "functional" web server using kixtart/kixforms and sockets - that would serve up real html documents in a multi-threaded-like-ish fashion ... for sure. |
|
Back to top |
|
 |
masken KiXforms Enthusiast

Joined: 14 Mar 2003 Posts: 202 Location: Gothenburg, Sweden
|
Posted: Tue Sep 28, 2004 12:35 pm Post subject: |
|
|
This is way cool  |
|
Back to top |
|
 |
Lonkero KiXforms Devotee


Joined: 13 Mar 2003 Posts: 1022 Location: Espoo, Finland
|
Posted: Sat Jun 11, 2005 11:38 am Post subject: |
|
|
don't work though...
need to get cracking. _________________ Hammer |
|
Back to top |
|
 |
Lonkero KiXforms Devotee


Joined: 13 Mar 2003 Posts: 1022 Location: Espoo, Finland
|
Posted: Sat Jun 11, 2005 11:50 am Post subject: |
|
|
no, it works.
the default answer just wasn't right for script query  _________________ Hammer |
|
Back to top |
|
 |
benny69 KiXforms Advocate


Joined: 30 Oct 2003 Posts: 567 Location: Lincoln, Ne
|
|
Back to top |
|
 |
Lonkero KiXforms Devotee


Joined: 13 Mar 2003 Posts: 1022 Location: Espoo, Finland
|
Posted: Sat Jun 11, 2005 3:08 pm Post subject: |
|
|
already using this in my adblocker script :p _________________ Hammer |
|
Back to top |
|
 |
benny69 KiXforms Advocate


Joined: 30 Oct 2003 Posts: 567 Location: Lincoln, Ne
|
Posted: Sat Jun 11, 2005 3:09 pm Post subject: |
|
|
ooo! adblocker script, I would like to see your script. _________________ Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta) |
|
Back to top |
|
 |
Lonkero KiXforms Devotee


Joined: 13 Mar 2003 Posts: 1022 Location: Espoo, Finland
|
Posted: Sat Jun 11, 2005 10:15 pm Post subject: |
|
|
nah, it's no so great...
uses server like this, hosts file and proxy override.
the reason why I needed it was proxy.
if you enable proxy, you get the commercials.
and if you leave out the server part, the commercials will be queried until timed out. _________________ Hammer |
|
Back to top |
|
 |
|