HTTP 与 TCP/IP,将数据发送到 Web 服务器

标签 http arduino tcp

我目前正在开展一个项目,我需要使用 Arduino Nano ( http://arduino.cc/en/Main/arduinoBoardNano ) 将数据从温度传感器发送到网络服务器。

起初我认为这很容易,因为有很多很棒的库可以帮助处理 POST/GET 等。但是,我的教授只是告诉我,我需要使用 TCP/IP 将数据发送到服务器,据我了解,POST 和 GET 是 HTTP 方法。

有人可以向我解释 HTTP 和 TCP/IP 之间的区别吗?特别是因为它涉及将数据发送到 Web 服务器。我正在寻找不太技术性的答案(我对所有这些都很陌生)。

最后,如果有人有使用 Arduino 执行我上面描述的操作的经验,我将不胜感激。

谢谢!

最佳答案

In Short: TCP is a transport-layer protocol, and HTTP is an application-layer protocol that runs over TCP.

Detail:To understand the difference (and a lot of other networking topics), you need to understand the idea of a layered networking model. Essentially, there are different protocols that let a computer talk at different distances and different layers of abstraction.

At the very bottom of the network stack is the physical layer. This is where electrical signals or light pulses or radio waves actually transmit information from place to place. The physical layer doesn't really have protocols, but instead has standards for voltages, frequencies, and other physical properties. You can transmit information directly this way, but you need a lot of power or a dedicated line, and without higher layers you won't be able to share bandwidth.

The next layer up is the link layer. This layer covers communication with devices that share a physical communications medium. Here, protocols like Ethernet, 802.11a/b/g/n, and Token Ring specify how to handle multiple concurrent accesses to the physical medium and how to direct traffic to one device instead of another. In a typical home network, this is how your computer talks to your home "router."

The third layer is the network layer. In the majority of cases, this is dominated by Internet Protocol (IP). This is where the magic of the Internet happens, and you get to talk to a computer halfway around the world, without needing to know where it is. Routers handle directing your traffic from your local network to the network where the other computer lives, where its own link layer handles getting the packets to the right computer.

Now we are getting somewhere. We can talk to a computer somewhere around the world, but that computer is running lots of different programs. How should it know which one to deliver your message to? The transport layer takes care of this, usually with port numbers. The two most popular transport layer protocols are TCP and UDP. TCP does a lot of interesting things to smooth over the rough spots of network-layer packet-switched communication like reordering packets, retransmitting lost packets, etc. UDP is more unreliable, but has less overhead.

So we've connected your browser to the web server software on the other end, but how does the server know what page you want? How can you post a question or an answer? These are things that application-layer protocols handle. For web traffic, this is the HyperText Transfer Protocol (HTTP). There are thousands of application-layer protocols: SMTP, IMAP, and POP3 for email; XMPP, IRC, ICQ for chat; Telnet, SSH, RDP for remote administration; etc.

These are the five layers of the TCP/IP networking model, but they are really only conceptual. The OSI model has 7 layers. In reality, some protocols shim between various layers, or can work at multiple layers at once. TLS/SSL for instance provides encryption and session information between the network and transport layers. Above the application layer, Application Programming Interfaces (APIs) govern communication with web applications like Quora, Twitter, and Facebook.

关于HTTP 与 TCP/IP,将数据发送到 Web 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23157817/

相关文章:

tcp - TCP 是否扩展到快速网络?

HTTP 状态 504

c++ - 如何在C++中将 float 组转换为字节数组(Arduino)

c++ - Arduino代码: shifting bits seems to change data type from int to long

ssl - SIM800L GSM 模块使用 http 工作,但使用 https 时显示错误,为什么?

mysql - 如何给mysql服务器添加一个端口

php - 为什么 http_parse_headers 在我的 cli 脚本中未定义?

http - RestSharp RestClient 的默认超时值是多少?

c - 实现 HTTP 1.0 服务器时出现的问题

java - 通过套接字同时发送和接收数据