exceptions the following exceptions are defined by the socket module error this exception is raised for socketor address-related errors it returns pair (errnomesgwith the error returned by the underlying system call inherits from ioerror herror error raised for address-related errors returns tuple (herrnohmesgcontaining an error number and error message inherits from error gaierror error raised for address-related errors in the getaddrinfo(and getnameinfo(functions the error value is tuple (errnomesg)where errno is an error number and mesg is string containing message errno is set to one of the following constants defined in the socket moduleconstant description eai_addrfamily eai_again eai_badflags eai_badhints eai_fail eai_family eai_memory eai_nodata eai_noname eai_protocol eai_service eai_socktype eai_system address family not supported temporary failure in name resolution invalid flags bad hints nonrecoverable failure in name resolution address family not supported by host memory allocation failure no address associated with node name no node name or service name provided protocol not supported service name not supported for socket type socket type not supported system error timeout exception raised when socket operation times out this only occurs if timeout has been set using the setdefaulttimeout(function or settimeout(method of socket object exception value is string'timeoutinherits from error example simple example of tcp connection is shown in the introduction to this the following example illustrates simple udp echo serverudp message server receive small packets from anywhere and print them out import socket socket socket(socket af_inetsocket sock_dgrams bind(("", )while truedataaddress recvfrom( print("received connection from %sstr(address) sendto( "echo:dataaddressf lib fl ff