Network programming in the 6.python

Source: Internet
Author: User

Support for multiple address families in Python

Among them, the most common of the first Berkeley sockets is Af_unix,

The sockets in Linux are Af_netlink,

Another feature for Linux (added in Python 2.6 ) is the support for transparent interprocess communication (TIPC) On.TIPC allows machines in a cluster of computers to communicate with each other without using IP -based addressing. Python on TIPC 's support is presented in the AF_TIPC family Way.

< Span class= "Fontstyle2" > family name af_inet address family: < Span class= "Fontstyle2" > Internet. Another address family af_inet6 for 6 version of the Internet Protocol (ipv6

< Span class= "Fontstyle2" > 1. Creating sockets

to create a socket, you must use the Socket.socket () function, which generally has the following syntax.
sockets (Socket_family, Socket_type, protocol=0)
where socket_family is Af_unix or af_inet (as mentioned earlier), Socket_type is Sock_stream
or Sock_dgram (as mentioned earlier). Protocol is usually omitted and defaults to 0.
therefore, in order to create a TCP/IP socket, you can call Socket.socket () in the following way.
Tcpsock = Socket.socket (socket.af_inet, socket. SOCK_STREAM)
Similarly, in order to create a UDP/IP socket, the following statement needs to be executed.
udpsock = Socket.socket (socket.af_inet, socket. SOCK_DGRAM)
/span>

Tips: Using from Socketimport *, you can write Udpsock = socket (socket.af_inet, socket) directly. SOCK_DGRAM), do not add the module name socket before each function name.

Socket built-in methods

In general, the simple standard process is:

Network programming in the 6.python

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.