Link to home
Start Free TrialLog in
Avatar of sindhu hegde
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.,
Avatar of Kimputer
Kimputer

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

User generated image
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

This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members 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.