Socket programming 2: tcp, udp, and socketudp
In the previous article, I talked about some basic knowledge about computer networks and introduced socket. From this section, I started to get started.
1 Probability
TCP: Transimission Control Protocol Transmission Control Protocol.
UPD: User datav Protocol User data packet Protocol.
Both belong to the transport layer protocol, the fourth layer in the OSI model described in the previous article.
Comparison:
- TCP is connection-oriented, and UDP is non-connection-oriented)
- Slow TCP transmission speed and fast UDP transmission speed)
- TCP has a packet loss retransmission mechanism, but UDP does not; (Retransmission)
- TCP ensures data correctness and UDP may cause packet loss (correctness)
- TCP is suitable for transmitting a large amount of data, and UPD is suitable for transmitting a small amount of data. (Data volume)
2. TCP link Process
3. UDP Link
* Both images are from the network.
Socket programming
Socket is an API for TCP/IP networks. programmers use socket interfaces to exchange data.
What is the relationship between SOCKET and TCP and UDP?
SOCKET is an API for Java to implement data communication.
This term originated from BSD-related UNIX and is the name of the API used for communication between processes in program development.
TCP/UDP is the two communication modes defined in Layer 4 of the OSI model.
That is to say, SOCKET is an API, and TCP/UPD is a communication protocol. The two are fundamentally different.
Example of language expression:
Use SOCKET to implement TCP (or UDP) communication. (On the contrary, TCP or UDP communication can also be implemented without SOCKET)
Differences between Socket and TCP/IP Programming
A Socket interface is an API of a TCP/IP network. A Socket interface defines many functions or routines that can be used by programmers to develop applications on a TCP/IP network. To learn TCP/IP network programming on the Internet, you must understand the Socket interface.
Socket is also a file descriptor. You can write IP addresses and port numbers to establish TCP/UDP connections.
It's easy to learn about socket. You can look at Windows network programming.