KiXforms Forum Index KiXforms
The Forum for the KiXforms Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Quick Links 
Site News
Downloads
Documentation
Donations
Script Archive
Tracking Systems

Build your own WebServer with Kixforms sockets.

 
Post new topic   Reply to topic    KiXforms Forum Index -> Discussion
View previous topic :: View next topic  
Author Message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Mon Aug 30, 2004 3:19 pm    Post subject: Build your own WebServer with Kixforms sockets. Reply with quote

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
View user's profile Send private message
Bonji
KiXforms Aficionado
KiXforms Aficionado


Joined: 10 Mar 2003
Posts: 393
Location: Virginia

PostPosted: Mon Aug 30, 2004 3:25 pm    Post subject: Reply with quote

Very nice Shawn!

This gets the little motor in my head spinning.

_________________
-Ben
Back to top
View user's profile Send private message
Jochen
KiXforms Devotee
KiXforms Devotee


Joined: 05 Mar 2003
Posts: 1204
Location: Stuttgart, Germany

PostPosted: Mon Aug 30, 2004 3:29 pm    Post subject: Reply with quote

eh... neat !
_________________
Jochen

Tell me, and I will forget.
Show me, and I may remember.
Involve me, and I will understand.
Back to top
View user's profile Send private message MSN Messenger
Jochen
KiXforms Devotee
KiXforms Devotee


Joined: 05 Mar 2003
Posts: 1204
Location: Stuttgart, Germany

PostPosted: Mon Aug 30, 2004 3:32 pm    Post subject: Reply with quote

hmmm...

you fergot to code exitclick() and clearclick() though.
Still the picture got through Very Happy

_________________
Jochen

Tell me, and I will forget.
Show me, and I may remember.
Involve me, and I will understand.
Back to top
View user's profile Send private message MSN Messenger
Lonkero
KiXforms Devotee
KiXforms Devotee


Joined: 13 Mar 2003
Posts: 1022
Location: Espoo, Finland

PostPosted: Mon Aug 30, 2004 8:50 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website MSN Messenger
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Mon Aug 30, 2004 9:22 pm    Post subject: Reply with quote

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
View user's profile Send private message
masken
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 14 Mar 2003
Posts: 202
Location: Gothenburg, Sweden

PostPosted: Tue Sep 28, 2004 12:35 pm    Post subject: Reply with quote

This is way cool Very Happy
Back to top
View user's profile Send private message MSN Messenger
Lonkero
KiXforms Devotee
KiXforms Devotee


Joined: 13 Mar 2003
Posts: 1022
Location: Espoo, Finland

PostPosted: Sat Jun 11, 2005 11:38 am    Post subject: Reply with quote

don't work though...
need to get cracking.

_________________
Hammer
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Lonkero
KiXforms Devotee
KiXforms Devotee


Joined: 13 Mar 2003
Posts: 1022
Location: Espoo, Finland

PostPosted: Sat Jun 11, 2005 11:50 am    Post subject: Reply with quote

no, it works.
the default answer just wasn't right for script query Razz

_________________
Hammer
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
benny69
KiXforms Advocate
KiXforms Advocate


Joined: 30 Oct 2003
Posts: 567
Location: Lincoln, Ne

PostPosted: Sat Jun 11, 2005 2:23 pm    Post subject: Reply with quote

Ya, this works with IE6 if you use http://127.0.0.1 or your loacl IP instead of http://hostname
_________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)
Back to top
View user's profile Send private message Send e-mail
Lonkero
KiXforms Devotee
KiXforms Devotee


Joined: 13 Mar 2003
Posts: 1022
Location: Espoo, Finland

PostPosted: Sat Jun 11, 2005 3:08 pm    Post subject: Reply with quote

already using this in my adblocker script :p
_________________
Hammer
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
benny69
KiXforms Advocate
KiXforms Advocate


Joined: 30 Oct 2003
Posts: 567
Location: Lincoln, Ne

PostPosted: Sat Jun 11, 2005 3:09 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Lonkero
KiXforms Devotee
KiXforms Devotee


Joined: 13 Mar 2003
Posts: 1022
Location: Espoo, Finland

PostPosted: Sat Jun 11, 2005 10:15 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group