sindhu hegde
asked on
TCP Server can act as http server
Hi!
The application to be developed consists of Webserver and the TCP Server. The TCP server listens to specific port and keeps on sending Keepalive and messages. While the HTTP server accepts user input and send the data to the TCP Server. So my question here is whether the TCP server can act as the HTTP Server. If so how can this be scheived. I am using Poco C++ libraries for HTTP and TCP server If there is some example please can you guid me here.,
The application to be developed consists of Webserver and the TCP Server. The TCP server listens to specific port and keeps on sending Keepalive and messages. While the HTTP server accepts user input and send the data to the TCP Server. So my question here is whether the TCP server can act as the HTTP Server. If so how can this be scheived. I am using Poco C++ libraries for HTTP and TCP server If there is some example please can you guid me here.,
You asked, "TCP server can act as the HTTP Server?"
Yes. And unlikely you'll really do this. This would mean you'd be redeveloping Apache or some other server which has 1000s of human years of development.
If you have unlimited time + budget, this might be an instructive adventure.
Better to just let Apache be Apache + write some sort of API server.
Yes. And unlikely you'll really do this. This would mean you'd be redeveloping Apache or some other server which has 1000s of human years of development.
If you have unlimited time + budget, this might be an instructive adventure.
Better to just let Apache be Apache + write some sort of API server.
Reading this, "The TCP server listens to specific port and keeps on sending Keepalive and messages" sounds like this is a 2nd Webserver.
Might be useful for you to open another question talking specifically about what you're trying to accomplish with your TCP server code.
Might be useful for you to open another question talking specifically about what you're trying to accomplish with your TCP server code.
Based on your question, it appears you're talking about two different protocols here. On the OSI model below, a TCP based server operates at Layer 4, whereas a HTTP server is a Layer 7 protocol. Yes, a TCP server can listen on any port, typically 80 or 443 for HTTP, but it needs to also be able to interpret the HTTP protocol, which has specific versions, requirements and request methods (GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, CONNECT, PATCH), etc.
In reality, you can probably accomplish your intended goal using existing tools without reinventing the wheel.
For example, you can run a simple HTTP server using Python:
You can then use netcat, for example, to send the keep alive or whatever you'd like using a looping/time-delayed script.
In reality, you can probably accomplish your intended goal using existing tools without reinventing the wheel.
For example, you can run a simple HTTP server using Python:
python -m SimpleHTTPServer 80
You can then use netcat, for example, to send the keep alive or whatever you'd like using a looping/time-delayed script.
# printf "GET / HTTP/1.0\r\n\r\n" | nc 127.0.0.1 80
# printf "GET / HTTP/1.1\r\nHost: localhost\r\n\r\n" | nc 127.0.0.1 80
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
It's not really achievable, unless you really want VERY VERY simple HTTP stuff (only show static pages), though that will still take some time.