Home > Backend Development > Python Tutorial > Summary of functions commonly used in python network programming

Summary of functions commonly used in python network programming

高洛峰
Release: 2016-10-20 10:24:03
Original
1557 people have browsed it

Summarize the functions commonly used in python network programming

socket.getservbyname(servicename[, protocolname]) –> integer
   
查询某个协议对应的端口号,需要使用两个参数,servicename对应端口名称,如 http, smtp,等。protocolname对应tcp,udp。
Copy after login
s.getsockname()
s.getpeername()
Copy after login

getsockname: Return the address of the local endpoint. For IP sockets, the address info is a pair (hostaddr, port)

getpeername: Return the address of the remote endpoint.For IP sockets, the address info is a pair (hostaddr, port). Related socket.gaierror

Socket.herror related to other address errors

Socket.timeout related to processing timeout after calling settimeout() on a socket

When using connect() call, the program can solve it There is a problem in converting the host name into an IP address. If the host name is incorrect, socket.gaierror will be generated. If there is a problem connecting to the remote host, socket.error will be generated.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template