TCP Server can act as http server

sindhu hegde
sindhu hegde used Ask the Experts™
on
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.,
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
It depends what the current HTTP can do and can't do. Even if it can do a bit, to be a fully fledged HTTP server from the like of Apache etc, will mean you need to do a LOT of programming (probably about 100 man hours per day over the course of 20 years, as that's about the same amount of energy used to build Apache from the ground up until now).
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.
David FavorFractional CTO
Distinguished Expert 2018

Commented:
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.
David FavorFractional CTO
Distinguished Expert 2018

Commented:
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.
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.

OSI-Model.png
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

Open in new window


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

Open in new window

# printf "GET / HTTP/1.1\r\nHost: localhost\r\n\r\n" | nc 127.0.0.1 80

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial