Socket Communications Principle (1)

    For TCP / IP, UDP, Socket programming these words you will not be familiar with it? With the development of network technology, these words are filled with our ears. So I want to ask:

  1. What is TCP / IP, UDP?
  2. Where Socket in it?
  3. Socket What is it?
  4. You can use them?

What is TCP / IP, UDP?

    TCP / IP (Transmission Control Protocol / Internet Protocol) Transmission Control Protocol / Internet Protocol, is a set of industry-standard protocols, it is for wide area networks (WANs) design.

    UDP (User Data Protocol, User Datagram Protocol) is corresponding with the TCP protocol. It is a kind of TCP / IP protocol suite.
Here is a map shows the relationship of these agreements.
Here Insert Picture Description
    TCP / IP protocol suite includes a transport layer, network layer, link layer. Now that you know the relationship between TCP / IP and UDP of the bar.

Where Socket in it?

    In Figure 1, we did not see the shadow Socket, then it Where is it? Or with plans to speak at a glance.
Here Insert Picture Description
    The original Socket here.

Socket What is it?

    Socket application layer and the intermediate software TCP / IP protocol suite to communicate abstraction layer, which is a set of interfaces. In design mode, Socket is actually a facade pattern, it is the complexity of TCP / IP protocol suite is hidden behind the Socket interface for users, a simple interface is all set, let Socket to organize data in order to comply with the specified protocol.

You can use them?

     Predecessors have given us to do a lot of things, communication between networks also a lot simpler, but after all, there are still a lot of work to do. Socket Programming heard before, that it is a more advanced programming knowledge, but as long as understand the working principle of Socket programming, also opened a mysterious veil.

     A-life scenarios. You want to call a friend, first dial telephone brought a friend after hearing the phone ring, then you and your friends established a connection, you can speak. And other end of the exchange, hang up the phone to end this conversation. Life scenarios to explain this works, perhaps TCP / IP protocol suite that is born in life, this is not necessarily.
Here Insert Picture Description
     Start talking about the server side. Server initialized Socket, then the port binding (bind), listens to port (listen), accept blocked calls, waiting for client connections. At this point if you have a client initiates a Socket, then connect to the server (connect), if the connection is successful, then connect the client and the server is established. The client sends a data request, the server receives the request and processes the request, and then sends the response data to the client, the client reads the data, and finally close the connection, ends of an interaction.

Published 25 original articles · won praise 7 · views 2159

Guess you like

Origin blog.csdn.net/qq_41506111/article/details/102775251