Answer the question
In order to leave comments, you need to log in
DIY web server
Good day. Gentlemen, tell me some mana on how to develop your own server, something like Selenium. I want my own bike, and not to take it ready. Thank you.
PS Or not bother with the search and get into the source of the finished products and use them as a guide?
Answer the question
In order to leave comments, you need to log in
Here are a couple of useful links: citforum.ru/programming/unix/sockets/ and allasm.ru/set_12.php
In general, the logic under Windows and nix is the same. The most "difficult" thing in a web server is working with sockets. It works like this:
1. Initialize sockets;
2. Create (socket) - the OS will give us a new socket;
3. Set up the socket (setsockopt);
4. Associate (bind) this socket with IP and port;
5. We begin to “listen” (listen) to the socket - in general, the OS listens, and we only process the data;
6. In the loop we accept (accept) connections - accept returns control and a new socket as soon as a request appears for the previously specified port and ip (otherwise it will return INVALID_SOCKET);
7. We start asynchronous (for verification / tests everything can be done in one thread) receiving data (recv) from the received socket;
8. We process the received data.
9. We send the answer (send);
10. After the end of the reception, close the socket;
11. We return to the beginning of the cycle - point 6.
Of course, with asynchronous processing, the cycle will only receive new sockets and give them to "workers" - worker threads.
In parentheses are socket API calls, under Linux almost everything is the same.
Under Windows all sockets are in Ws2_32.dll .
If something is not clear, I will answer to the best of my knowledge 8)
I do not think that there is sensible mana on this topic from the practical side, and the theoretical side may not be enough.
Maybe the source code idea isn't so bad after all.
Only Selenium is not a server, but a client. It automates the browser from the client side.
It is not clear what Selenium has to do with it, which is not a server, but a browser plugin and a library for interacting with it.
Just in case, I will give a link: docs.python.org/3.3/library/http.server.html
Read a series of articles about 10,000 connections . There, the guys write their server from scratch and face various problems. Great for basic understanding. The algorithm is, in principle, as described by VoidVolker.
mongoose is easy to understand (in the source code)
sorry, I didn’t notice the tag (why am I subscribed to python?)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question