Summarize the functions commonly used in Python network programming
Socket.getservbyname (servicename[, ProtocolName]) –> integer queries the port number of a protocol, requires two parameters, servicename corresponding port name, such as HTTP , SMTP, and so on. ProtocolName corresponds to 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).
Exception for Socket
Socket.error related to General I/O and communication issues
Socket.gaierror related to querying address information
Socket.herror related to other address errors
After a socket is raised with settimeout (), the processing timeout is related to the Socket.timeout
When using the call of Connect (), the program can solve the problem of converting the hostname to an IP address, if the hostname is not socket.gaierror, if there is a problem connecting the remote host, it will produce socket.error.