I have a single-threaded FastCGI "Hello, World!" application, there are some code:
error = FCGX_Init();
// error handling
socket_descriptor = FCGX_OpenSocket("127.0.0.1:1500", 5);
// error handling
error = FCGX_InitRequest(&request, socket_descriptor, 0);
// error handling
std::cout << "Awaiting connect...";
bytes_accepted = FCGX_Accept_r(&request);
// error handling
std::cout << "OK!" << std::endl;
FCGX_PutS("<title>Hello!</title>\r\n", request.out)
FCGX_Finish_r(&request);
When I launch this code, open browser and do "127.0.0.1:1500", browser says "Connection reset" and code outputs nothing like "OK", FCGX_Accept_r seems to be freezing.
I tried to open appropriate port on my Debian 9 x64 with an iptables:
iptables -A INPUT -i eth0 -p tcp --destination-port 1500 -j ACCEPT
iptables-save
but it causes no effect.
What am I doing wrong?
When you don't specify a schema in the url and the port isn't specific to any particular protocol that the browser understands, so the browser will assume http:// (or maybe https these days?). Your program expects fastcgi instead, which is a different protocol, and the library doesnt understand HTTP. Probably the request will never be accepted.
Fastcgi is a protocol for communicating with a web server. You need to use a web server that accepts http requests an forwards those requests using fastcgi protocol. For example, nginx supports the protocol.