Learn Python Basics--------7 Network programming

Source: Internet
Author: User

Sockets

Sockets are computer network data structures, which embody the concept of communication nodes, before any type of communication begins, a network application must create a socket, which can be likened to a telephone jack, without which he will not be able to communicate.

The socket was first the Berkeley version of the University of California, Unix (Unix BSD) sockets, called Bokeli Sockets or BSD sockets. Sockets are originally created for applications on the same host, allowing one program (aka one process) running on the host to communicate with another running program. This is called process communication, with two types of sockets: file-based and network-oriented

The UNIX socket is the first socket family and has a family name Af_unix, which represents the address family: UNIX

Because two processes are running on the same computer, these sockets are based on files, which means that the file system supports their underlying infrastructure, which makes sense because the file is a constant between multiple processes running on the same host.

The second type of socket is network-oriented, and it has its own family name, Af_inet, or family: the Internet. Another family Af_inet6 for 6th Edition Internet Protocol (IPV6) addressing

Connection-oriented sockets and non-connected sockets

1. Connection-oriented sockets

A connection-oriented socket means that a connection must be established before communication, such as using a telephone system to call a friend. This type of communication we call virtual circuits or stream sockets.

Communicating with connected traffic provides serialized, reliable, and non-repeatable data delivery without logging boundaries, which basically means that each piece of information can be split into multiple fragments, and each piece of information can be guaranteed to reach the destination, then combine it sequentially, and then pass the complete message to the waiting application.

The primary protocol that implements this type is Transmission Control protocol TCP, in order to create a TCP socket, you must use Sock_stream as the nested byte type. The name of the TCP socket is sock_stream based on one of the representations of the stream socket. Because the network version of these sockets (AF_INET) uses Internet Protocol IP to search for hosts in the network, the entire system is combined with both protocols (TCP and IP)

2. No connection socket

A non-connected socket is called a datagram type of socket, communication does not establish a connection, transmission can not guarantee the repeatability, the sequence, the reliability, may be sent overall. It is better at lower cost performance.

The primary protocol that implements this type of connection is User Datagram Protocol UDP. In order to create a UDP socket, it is necessary to use SOCK_DGRAM as the socket type, because these sockets also use the Internet Protocol to find the network host, so there is a more common name udp/ip

In addition, there are

socket.SOCK_RAW     #原始套接字,普通的套接字无法处理ICMP、IGMP等网络报文,而SOCK_RAW可以;其次,SOCK_RAW也可以处理特殊的IPv4报文;此外,利用原始套接字,可以通过IP_HDRINCL套接字选项由用户构造IP头。

socket.SOCK_RDM  #是一种可靠的UDP形式,即保证交付数据报但不保证顺序。SOCK_RAM用来提供对原始协议的低级访问,在需要执行某些特殊操作时使用,如发送ICMP报文。SOCK_RAM通常仅限于高级用户或管理员运行的程序使用。

A simple local

Learn Python Basics--------7 Network programming

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.