总结一下python网络编程中常用到的函数
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).
立即学习“Python免费学习笔记(深入)”;
Socket的异常
与一般I/O和通信问题有关的 socket.error
与查询地址信息有关的 socket.gaierror
与其他地址错误有关的 socket.herror
与在一个socket上调用settimeout()后,处理超时有关的socket.timeout
使用connect()的调用的时候,程序可以解决把主机名转换成IP地址的问题,若主机名不对会产生socket.gaierror,若连接远程主机有问题,会产生socket.error。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2283452.html