Networking – If HTTP runs on a port, does that mean TCP can also run on that port

3ghttpmobile phonenetworkingtcp

I'm building an app that needs to run on a mobile smartphone over a GPRS/3G network. I'm doing bit ops, so every byte wasted through HTTP headers is bad. Mobile providers in my area make heavy use of proxies and the like. Websockets for one don't work.

HTTP on port 80 and 443 seems to always work, but does that mean that I can create a TCP socket connection to my server on the same port and start a bi-directional communication? I don't think mobile apps like WhatsApp, Viber etc. use HTTP connections, but I haven't find any details on their implementations and if they do anything to make the network work flawlessly over 3G, or if it just works as it is.

Best Answer

TCP and HTTP are different things.

TCP is the transport layer. By definition, it's responsible for carrying application layer protocols (HTTP in your case) over it. TCP does not run over a port. It is the arbitrator of ports. In other words, when you connect to an HTTP server, you connect on TCP port 80. When you connect to HTTPS, you're connecting over TCP port 443.

HTTP and HTTPS can run over any TCP port. 80 and 443 are just the common ones. You can make any application listen on those ports if you want. So yes, you can connect to your server over port 80 using some other protocol instead of HTTP, but only if the server is configured to listen on that port using that other protocol, and only if HTTP or HTTPS are configured to not use those ports (assuming you're running a web server on it).

Now, you mentioned that your provider is making use of a proxy. Can you make a non-HTTP/HTTPS connection over port 80 or 443? That depends on how smart the proxy is. If it's performing packet inspection, it could be verifying the HTTP headers to make sure that the traffic going over those ports is indeed HTTP traffic. There are ways to fake it, but it depends on how deeply the proxy is inspecting the traffic. If the proxy is blocking non-HTTP/HTTPS traffic on HTTP/HTTPS ports, then there isn't much you can do about it except squawk at your provider (or pay the higher price as the case may be).

When it comes to how various mobile applications communicate, it all depends on how the vendor wrote them. Most use HTTP or HTTPS over port 80 or 443 respectively because most mobile apps are just skinned web apps. But there's no rule that says they have to, and there's no real way for you to know unless you sniff the packets somehow.

I hope I have answered your question.

Related Question