Hello. Hope all is well.
I’ve been playing around with websockets for a while now and made a simple http webserver. The server is able to handle a request for a HTML page and all subsequent requests related to it. What the server does is simply to read the requested files to an char array in binary mode and return the package / array together with relevant headers.
Now I wonder, is that really the best way to do it? To send back a file bit by bit like that for every request that comes in?
Apache on XAMPP, for example. If you enter localhost then your entire root folder is already available for the client / browser. What is happening here and how does it work?
Maybe this will help… How can I create my own server with “directory browsing/listing” ?
That should be as easy as looping over all files / directories in the root directory and displaying that in a nice HTML format I’d say.
I don’t know what language you’re using, but almost all of them supply a way to iterate over the contents of a directory.
Hey man. Hope you are doing well. Yes. It seems to be correct. There is no magic behind it.
But when servers and web browsers make these file transfers all the time, it seems reasonable that bytes are lost on the road on some occasions? What are some common steps to make the transfer more bulletproof, without costing too much time
Well if you’re using TCP (which HTTP does) then that is responsible for making sure all data gets from A to B correctly, and retry when stuff goes wrong. You don’t need to worry about that in your server at all.
You should look into the OSI model. HTTP is the application layer (level 7) and TCP is the transport layer (layer 4 iirc).
Yes. That’s what I’m using (TCP), no problem so far.
I also noticed that the browser never stops loading / receiving, unless I specify the correct content length. Does this mean that the browser never stops loading if I enter too many characters by mistake?
I wouldn’t know. What happened when you tried?
I guess it waits for the whole length because It never stops loading. It seems that surgical precision is required here
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.