The connection and difference between TCP,UDP and Socket,http __ Smart Home

Source: Internet
Author: User
because recently do a smart home project, the first to communicate with the socket, in order to first use UDP to judge the intranet outside the network to establish links, and then use TCP real-time communication. first understand the definition

Advantages of http://www.360doc.com/content/14/0325/09/1317564_363500997.shtml TCP:

Reliable, stable
TCP is a reliable embodiment of TCP in the transfer of data, there will be three handshake to establish the connection, and in the data transmission, there are confirmation, window, retransmission, congestion control mechanism, after the data is passed, will also disconnect to save the system resources TCP disadvantage:

Slow, low efficiency, high system resources, easy to attack
TCP must first build a connection before it passes data. This will consume time, and in the data transmission, validation mechanism, retransmission mechanism, congestion control mechanism will consume a lot of time, and to maintain all the transmission connections on each device, in fact, each connection will occupy the system's CPU, memory and other hardware resources.
Moreover, because TCP has the confirmation mechanism, three times handshake mechanism, these also causes TCP to be easy to use, realizes DOS, DDOS, CC and so on attack. the advantages of UDP:

Faster, a little more secure than TCP.
UDP has no TCP handshake, acknowledgement, window, retransmission, congestion control mechanism, UDP is a stateless transport protocol, so it is very fast when passing data. Without these mechanisms of TCP, UDP is less vulnerable than TCP is exploited by attackers. But UDP also can not avoid the attack, for example: UDP flood attack ... Disadvantages of UDP:

unreliable, unstable
Because UDP does not have TCP those reliable mechanism, when the data passes, if the network quality is bad, can easily lose the package.

Based on the pros and cons of the above, then: when should you use TCP:

when the quality of network communication requirements, such as: the entire data to be accurate to pass to
each other, this is often used for a number of reliable applications, such as HTTP, HTTPS, FTP, etc.
protocol for transferring files, POPs, SMTP, and other mail transport protocols.
in daily life, the common use of the TCP protocol is as follows:

browsers, using the HTTP
FlashFXP, using FTP
Outlook, using POPs, SMTP
Putty, with Telnet, SSH
QQ File Transfer
............ when should you use UDP:

when the network communication quality requirements are not high, the request network communication speed can be as fast as possible, then you can
to use UDP.
For example, in daily life, the common use of the UDP protocol is as follows:

QQ Voice
QQ Video
Tftp

1, TCP/IP is a protocol group, can be divided into three levels: Network layer, Transport layer and application layer.

At the network layer are: IP protocol, ICMP protocol, ARP protocol, RARP protocol and BOOTP protocol.
In the transport layer there are: TCP protocol and UDP protocol.
In the application layer are: FTP, HTTP, TELNET, SMTP, DNS and other protocols.
Therefore, HTTP itself is a protocol that transmits hypertext from a Web server to a local browser. 2, the HTTP protocol is based on the request/response model.

The customer first establishes a TCP link to the server and sends a request to the server, which contains the request method, URI, protocol version, and the associated MIME-style message. The server responds to a status line that contains the protocol version of the message, a success and failure code, and the associated MIME style message.
Http/1.0 creates a new TCP link for each HTTP request/response, so a page containing HTML content and pictures will need to establish multiple short TCP links. The establishment of a TCP link will require 3 handshake.
In addition, in order to obtain the appropriate transmission speed, TCP will need to spend additional loop link time (RTT). Each link is built with this recurring overhead, which does not carry actual useful data, but only guarantees the reliability of the link, so http/1.1 proposes a sustainable link implementation approach. http/1.1 will only establish a TCP link and use it repeatedly to transmit a series of request/response messages, thus reducing the number of links established and the frequent link overhead. 3. Conclusion:

Although HTTP itself is a protocol, it is ultimately based on TCP. However, at present, some people are studying the HTTP protocol based on TCP+UDP Hybrid. What's the socket?

The socket is the intermediate software abstraction layer of the application layer communicating with the TCP/IP protocol family, which is a set of interfaces. In design mode, the socket is actually a façade mode, which is the complex TCP/IP protocol family hidden behind the socket interface, for users, a group of simple interface is all, let the socket to organize data to meet the specified protocol

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.