Python Socket Detailed

Source: Internet
Author: User

The socket () function is used to assign a description word of a set of interfaces and the resources it uses, based on the specified address family, data type, and protocol. If the Protocol protocol is unspecified (equals 0), the default connection method is used. Only one protocol is supported for a particular set of interfaces that use a given address family. However, the address family can be set to Af_unspec (unspecified) so that the protocol parameters are specified. The protocol number is specific to the communication domain in which the communication is made.    create a set of interfaces (). #include <winsock.h>socket PASCAL far SOCKET (int af, int type, int protocol); AF: An address description. Currently, only the af_inet format is supported, that is, ARPA Internet address format. Type: Specifies the socket type. The type description type of the new set of interfaces, such as TCP (SOCK_STREAM) and UDP (SOCK_DGRAM). Common socket types are sock_stream, Sock_dgram, Sock_raw, Sock_packet, Sock_seqpacket, and so on. Protocol: As the name implies, the protocol is specified. protocol used by the socket interface. If the caller does not want to specify, 0 is available. Commonly used protocols are, IPPROTO_TCP, IPPROTO_UDP, IPPROTO_SCTP, IPPROTO_TIPC, respectively, they correspond to TCP transport protocol, UDP Transmission protocol, STCP Transmission protocol, TIPC transmission protocol.    supports the following types of descriptions: type interpretation Sock_stream provides an ordered, reliable, bidirectional, and connection-based byte stream, using an out-of-band data transfer mechanism to use TCP for the Internet address family. The SOCK_DGRAM supports non-connected, unreliable, and datagram services that use a fixed-size (usually very small) buffer, using UDP for the Internet address family. The Sock_stream type of socket interface is a full bidirectional byte stream. For a stream class socket interface, it must be in a connected state before receiving or sending data. Use the Connect () call to establish a connection to another set of interfaces, after which the data can be transmitted using Send () and recv (). When the session ends, call Closesocket (). Out-of-band data is received as specified by Send () and recv (). The communication protocol that implements the SOCK_STREAM type socket interface guarantees that the data will not be lost or duplicated. If the terminal protocol has buffer space and the data cannot be sent successfully at a certain time, the connection is considered to be interrupted and subsequent calls will also be returned with a wsaetimeout error. Sock_dThe Gram type socket interface allows you to send or receive datagrams from any port using SendTo () and Recvfrom (). If such a socket is connected with connect () with a specified port, send () and recv () are available for sending and receiving datagrams with that port.

Python Socket Detailed

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.