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

Summary of functions commonly used in python network programming

高洛峰
高洛峰Original
2016-10-20 10:24:031418browse

Summarize the functions commonly used in python network programming

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

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.

Statement:
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