SoFunction
Updated on 2024-11-20

What is socket network communication in Python?

What's a socket?

Socket is an abstraction layer that connects the application layer to the transport layer and is a set of interfaces.

In Design Patterns, Socket is actually a facade pattern that hides the complex TCP/IP protocol family behind the Socket interface, and a simple set of interfaces is all it takes for the user to let the Socket organize the data to conform to the specified protocol.

Therefore, we do not need to deeply understand the tcp/udp protocol, socket has been encapsulated for us, we only need to follow the provisions of the socket to program, write the program is to follow the natural tcp/udp standard. The establishment of a network communication connection at least a pair of port number (socket). socket is essentially a programming interface (API), the encapsulation of TCP/IP, TCP/IP also to provide programmers to do the network development of interfaces used, which is the Socket Programming Interface; HTTP is a sedan, provides a specific form of encapsulation or display of data; Socket is an engine Socket is the engine that provides the ability to communicate over the network.

This example describes how python uses sockets for simple network connections:

import socket
print "Creating socket...",
s = (socket.AF_INET, socket.SOCK_STREAM)
print "done."
print "Connecting to ",
(("", 80))
print "done."

The above code returns the following result:

Creating socket... done.
Connecting to  done.

This article on Python socket network communication is what the article is introduced to this, more related to Python socket network communication knowledge points summarize the contents of the search for my previous articles or continue to browse the following related articles I hope you will support me in the future more!