Create a great and really fast Web Server with Basic4PPC!

sitajony

Active Member
Licensed User
Hi, since few months I didn't know how create a web server on our PPC, I beleive that we've to use a lot of Library with a lot of Mb lol...
In fact it's easy to create our own web server with Basic4PPC...
You just need Network.dll and Binary.dll...

For beginig, you need to create a Server on PORT "80":
Server.New1(80)

Then you must to declare the Client class:
Client.New1

Now you can start you server but it's not finish ;)
Server.Start

You need to create a Timer like the Network.dll example and set interval to 500ms or other and enable it...
wait.Interval=500
wait.Enabled=True

In the "wait" Tick sub you wait for request from a web navigator:
If Server.Pending Then 'Client coming in!

In this condition you accept his request from the navigator:
Client.Value=Server.Accept

Now with the Binary.dll you open the datas sended by the navigator, this datas contains the URL, Method (GET/POST), Variable set in POST Method and some usefull datas...:
bin.New2(Client.GetStream,1252)

Once that you've open the data you've to read this data as string... The datas sended by the navigator is in Byte[] format, you need to convert it in String format:
Dim buffer(4096) As byte
bin.ReadBytes(buffer(),
4096)
datas=bin.BytesToString(buffer(),
0,2048)


Now the "datas" variable contains the informations needed... This is an receive data example:

B4X:
GET / HTTP/1.1
Accept: image/jpeg, application/x-ms-application, image/
if, application/xaml+xml, image/pjpeg, application/x-ms-xbap, application/x-shockwave-flash, applicatio
/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
Accept-Language: fr-FR
User-Agent: Moz
lla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729
 .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0; In
oPath.2; .NET4.0C; .NET4.0E)
Accept-Encoding: gzip, deflate
Host: 127.0.0.1
Connection: Keep-Alive

In first line we can see the Method and the url asked by the navigator...
For split this values you just need to use the SubString() function and StrSplit():
Sub Globals
'Declare the global variables here.
Dim buffer(4096) As byte
Dim arg(3) AsString
End Sub
Sub getinfo(txt)
arg()=
StrSplit(SubString(txt,0,StrIndexOf(txt,CRLF,0))," ")
End Sub
With this function you get the Method name, URL asked and the protocol (Don't care with it)

Sorry I've to go... Will be finish in few hours...
Edit: Sorry I've not enough time in this moment... So be patient for see the end ;)
 
Last edited:
Top