python網絡編程中常用到的函數?總結
總結一下python網絡編程中常用到的函數socket.getservbyname(servicename[, protocolname]) –> integer查詢某個協議對應的端口號,需要...
總結一下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。
本文由用戶 dfee 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!