I am writing a server in Linux that should serve as an API.
Initially, I wanted to make it multithreaded on the same port, which means that I will have several threads working with different requests received on the same port.
One of my friends told me that this is not how it should work. He told me that when the request is received, I must first follow the Handshake procedure, create a stream that listens to some other port dedicated to the request, and then redirect the requested client to the new port.
Theoretically, this is very interesting, but I could not find any information on how to implement a handshake and perform a redirect. Can anyone help?
If I am not mistaken in interpreting your answers, as soon as I create a multithreaded server with the main thread listening on the port and create a new thread for processing requests, do I essentially make it multithreaded on one port?
Consider a scenario in which I receive a large number of requests every second. Isn't it true that every port request should now wait for the "current" request to complete? If not, how the connection will be performed: let's say the browser sends a request, so the stream should first listen on the port, block it, process it, respond and then unlock it.
In this case, although I have "multithreading", all I use is one single thread at a time, except for the main thread, because the port is blocked.
source share