本文纯属个人见解,是对前面学习的总结,如有描述不正确的地方还请高手指正~
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).
Socket的异常
- 与一般I/O和通信问题有关的 socket.error
- 与询查地址息信有关的 socket.gaierror
- 与其他地址错误有关的 socket.herror
- 与在一个socket上调用settimeout()后,理处超时有关的socket.timeout
用使connect()的调用的时候,序程可以处理把主机名转换成IP地址的问题,若主机名不对会发生socket.gaierror,若连接远程主机有问题,会发生socket.error。
文章结束给大家分享下程序员的一些笑话语录: 真正的程序员喜欢兼卖爆米花,他们利用CPU散发出的热量做爆米花,可以根据米花爆裂的速度听出正在运行什么程序。