python网络编程-一些常用有用的函数
生活随笔
收集整理的這篇文章主要介紹了
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).
?
Socket的異常
- 與一般I/O和通信問題有關的 socket.error
- 與查詢地址信息有關的 socket.gaierror
- 與其他地址錯誤有關的 socket.herror
- 與在一個socket上調用settimeout()后,處理超時有關的socket.timeout
使用connect()的調用的時候,程序可以解決把主機名轉換成IP地址的問題,若主機名不對會產生socket.gaierror,若連接遠程主機有問題,會產生socket.error。
轉載于:https://www.cnblogs.com/roicel/archive/2013/02/26/2933154.html
總結
以上是生活随笔為你收集整理的python网络编程-一些常用有用的函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 去掉viewstate保持在页面中的一大
- 下一篇: websocket python爬虫_p