Web Server and HTTP.dll

berndgoedecke

Active Member
Licensed User
Longtime User
I have taken up the example of sitajony: http://www.b4x.com/forum/code-samples-tips/5956-create-great-really-fast-web-server-basic4ppc.html
I wanted to read out HTML-Forms and it works well except for one small thing.
To configure it out I use the localhost option in the "action" Parameter in the HTML. If the Server is started and the Datas are sent, the Browser(Firefox) search for localhost as long as the Server runs and shows a blank Website when the Server is quited. I think that is not a normal behavior.
I did attach the HTML example and the B4P-source for anyone who is interested in this subject.
Another question in this context: Is it possible to do the same with HTTP.dll and when it is, how it is to do?

Best regards

berndgoedeckeView attachment 6155
 

Attachments

  • HT.zip
    44.3 KB · Views: 254
Last edited:

sitajony

Active Member
Licensed User
Hello, it's me who have writen this Tuto but I've not finish sorry...
In your example you send nothing to the web browser, it's normal if it return a blank page...

You've to open your file with an other Binary object and read its bytes...
When you've sent your data you've to close the client otherwise the web browser search again in thinging that there's datas who are not sent yet...

I'll try to finish the "Tutorial" soon...
 

berndgoedecke

Active Member
Licensed User
Longtime User
Directory for localhost?

Hello sitjony,
excuse my late reply, but meanwhile, I have tested a lot to complete the loading from localhost.
It is right that there is no html to load from localhost, because I don't know where to place it. If Apache is installed the documentroute is configured in the httpd.conf file. But if Apache is running, it is logical that I can't register another Server with B4PPC on Port 80.
If I have one central html file, to link to some HTML-forms, I can transmit the form datas to the B4P-server and the "action" in the form tag could contain the link, back to the central html file.
The problem is, that there is a localhost(because I can ping 127.0.0.1) but there is no directory on it. How it is to configure. I think that it is to do with etc/hosts or etc/lmhosts but I didn't find a useful documentation about it.
A nother part of the problem is, that I use DHCP for LAN. Is it possible that it stops the loopback?
I'm thankful for any hints.

Best regards

berndgoedecke
 

sitajony

Active Member
Licensed User
Effectively, if you've an other program who use the PORT 80 you can't open an other on the same PORT...
But after I didn't understand, if you work on localhost your DHCP is not a problem...
If you want send data to the web browser you need just to send bytes like this:

bin.New1(Client.GetStream,true)
bin.SendBytes(bin.StringToByte("Test 1 2 3"))
Client.Close

If you want send an HTML file just open your html file with a binary object but not with FileRead() coz some format will be deleted like "è", "é" and the others file like "Jpeg", "Mp3"... will be not recognised by the web browser so it's better to create 2 binary object for send properly a file...

bin.New1(Client.GetStream,true)
htmlPath=apppath & "\www"
file="index.html"
size=fileSize(htmlPath & "\" & file)
FileOpen(c1,htmlPath & "\" & file,cRead)
bina.New1(c1,true)
Dim buffer(size) as Byte
bina.ReadByte(buffer(),0,size)
fileclose(c1)
bin.WriteByte(buffer(),0,size)
Client.Close
 

berndgoedecke

Active Member
Licensed User
Longtime User
Stream conversion error

Hello Sitajony,
I've integrated your code as a Sub. But I get a Stream conversion error as shown in the attached jpg.
What is wrong?


Best regards

berndgoedecke
 

Attachments

  • HT.zip
    18.7 KB · Views: 231

sitajony

Active Member
Licensed User
You opened your TempHtm.htm with a simple connection (StreamReader):
FileOpen(c1,htmlPath & "\" & file,cRead ,, cASCII)
and then you opened with a Binary object so it return an error...
You need to open it with cRandom:

FileOpen(c1,htmlPath & "\" & file,cRandom)
bina.New1(c1,True)

Normaly it'll works...
 
Top