浩晨众云网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
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).
使用connect()的调用的时候,程序可以解决把主机名转换成IP地址的问题,若主机名不对会产生socket.gaierror,若连接远程主机有问题,会产生socket.error。