首頁  >  文章  >  後端開發  >  python網路程式設計中常用到的函數總結

python網路程式設計中常用到的函數總結

高洛峰
高洛峰原創
2016-10-20 10:24:031498瀏覽

總結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 pairdmm (cair) the ftp. of the remote endpoint.  For IP sockets, the address info is a pair (hostaddr, port).


Socket的異常

與一般資訊與通訊問題有關的sockocet.errororoocket.有關的socket.gaierror

與其他位址錯誤有關的socket.herror

與在一個socket上呼叫settimeout()後,處理超時有關的socket.timeout

使用connect()的呼叫的時候,程式可以解決把主機名稱轉換成IP位址的問題,若主機名稱不對會產生socket.gaierror,若連接遠端主機有問題,會產生socket.error。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn