What are Sockets afterall ? and Why cant we use sockets instead of HTTP?

跟風遠走 提交于 2019-12-02 21:16:17
Richard JP Le Guen

I assume this is a very general question about the relationship between sockets and HTTP connections. I also assume that "HTTPConnection" does not refer to something involving a specific API/runtime/environment even though the way it's a camel cased term with spaces removed could suggest otherwise.

Now that that's out of the way, I present to you, the OSI model:

The OSI Model describes levels of abstraction for network communication. A socket is a concept which would exist somewhere on layer 3, the Network Layer, as part of the Internet Protocol (IP).

HTTP is higher abstraction than IP, usually regarded as being up in the Application Layer, at the "top" of the OSI model.

An Analogy

You could define a city's transportation and traffic at different "layers" the same way we define network stuffs.

  • At its simplest, a city is a bunch of buildings.
  • As the city grows people need to travel from building to building, so they develop roads. The roads are a new "layer" to the city.
  • As more people use the roads, they begin to need a system of rules and laws to help keep everyone safe.
  • Once people are safe on the roads though, they want the roads to be efficient and quick, so a system of lights and signs help coordinate people on the roads.

Two important things:

First, each layer depends on the one "below" it. Without buildings (destinations) roads become silly. Without roads, traffic laws are silly. Without traffic laws, traffic lights are silly.

Second, the specifics of the higher layers vary depending on the city you're in: sometimes you find yourself in a country where people drive on the left, sometimes they drive on the right. Sometimes you can turn on a red, sometimes not. Sometimes there are roads, but they are without laws.

End of Analogy

So on the Internet, sometimes you communicate with different kinds of servers. Underneath, they may all rely on sockets (the "roads" of he internet) but they all have their own "traffic laws" that you have to respect - protocols like HTTP or FTP or SOAP.

Http is a protocol built on top of sockets.

When you use Http, you're using a higher level of abstraction on top of sockets. You're still using sockets.

It's kind of like saying "Why would you use a .xyz document when you could just use a file?"

Read about the OSI model for network communcations: http://en.wikipedia.org/wiki/OSI_model It should do a good job of explaining where each of those components fit.

Lets say that socket is just a stream between 2 remote systems which uses TCP/IP or maybe UPD lower level protocols for transport data. And HTTP is the higher level protocol which specifies HOW systems are communicating.

Small example: air is a transport level for voice, but you need words (an upper level protocol) for communication with other ppl.

But better for you to read here: http://en.wikipedia.org/wiki/OSI_model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!