1. What is TCP/IP,UDP?
2. where is the socket?
3. What is a socket?
4. Will you use them?
What is TCP/IP ,UDP ?
TCP/IP (Transmission Control protocol/internet Protocol) is the transmission protocol/Inter-network protocol, is an industry-standard protocol set that is for WAN (WANs) is designed.
UDP (User Data Protocol, Subscriber Datagram Protocol) isThe protocol that corresponds to TCP. It is belong toOne of the TCP/IP protocol families.
Here is a diagram showing the relationship of these protocols.
Figure 1
The TCP/IP protocol family includes transport layer, network layer, and link layer. Now you know the relationship between TCP/IP and UDP.
Socket where is it?
in Figure 1, we don't see the socket shadow, so where is it? Or use a diagram to speak, at a glance.
Figure 2
OriginallyThe socket is here.
SocketWhat is it?
A socket is an intermediate software abstraction layer that the application layer communicates with the TCP/IP protocol family, which is a set of interfaces. In design mode, thesocket is actually a façade mode, it is the complex TCP/IP protocol family hidden behind the socket interface, for the user, a set of simple interface is all, let the socket to organize data to meet the specified protocol.
Will you use them?
predecessors have done a lot of things to us, the communication between the network is a lot simpler, but after all, there is still a lot of work to do. Previously heard socket programming, think it is more advanced programming knowledge, but as long as understand how the socket programming principle, the mysterious veil also opened.
a scene in the life. You have to call a friend, dial first, a friend hears a phone call, and then you and your friend establish a connection, you can talk. When the communication is over, hang up the phone and end the conversation. the scene in life explains this work principle, perhaps the TCP/IP protocol family is born in the life, this is not necessarily.
Figure 3
Start with the server side. The server-side initializes the Socket, then binds to the port (BIND), listens to the port (listen), calls the accept block, waits for the client to connect. At this point if a client initializes a Socket and then connects to the server (connect), the client-server connection is established if the connection is successful. The client sends the data request, the server receives the request and processes the request, then sends the response data to the client, the client reads the data, closes the connection, and ends the interaction at the end.
Starting with a simple TCP example using the socket programming, the basic steps are as follows:
Server Client
+++++++ ++++++++
Create a socket to create a socket
+++++++ ++++++++
| |
| |
| |
+++++++ ++++++++
Address Assignment (Address assignment value (
own address) server address)
+++++++ ++++++++
| |
| |
| |
++++++++ |
Bind with Bind |
Sockets and Addresses |
++++++++ |
| |
| |
| |
+++++++ |
Listen |
+++++++ |
| ++++++++++
| <------------------------------Connect server
| ++++++++++
+++++++ |
Accept |
+++++++ |
| |
| +++++++++
| Recv and send
| For data processing
| +++++++++
+++++++++ |
Receive with Accept |
Socket for |
Recv and send |
+++++++++ |
| |
| |
| |
+++++++++ +++++++++
Close socket Close Socket
+++++++++ +++++++++
. NET Socket Programming