python网络编程-一些常用有用的函数
查詢(xún)某個(gè)協(xié)議對(duì)應(yīng)的端口號(hào),需要使用兩個(gè)參數(shù),servicename對(duì)應(yīng)端口名稱(chēng),如 http, smtp,等。protocolname對(duì)應(yīng)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和通信問(wèn)題有關(guān)的 socket.error
- 與查詢(xún)地址信息有關(guān)的 socket.gaierror
- 與其他地址錯(cuò)誤有關(guān)的 socket.herror
- 與在一個(gè)socket上調(diào)用settimeout()后,處理超時(shí)有關(guān)的socket.timeout
使用connect()的調(diào)用的時(shí)候,程序可以解決把主機(jī)名轉(zhuǎn)換成IP地址的問(wèn)題,若主機(jī)名不對(duì)會(huì)產(chǎn)生socket.gaierror,若連接遠(yuǎn)程主機(jī)有問(wèn)題,會(huì)產(chǎn)生socket.error。
轉(zhuǎn)載于:https://www.cnblogs.com/roicel/archive/2013/02/26/2933154.html
總結(jié)
以上是生活随笔為你收集整理的python网络编程-一些常用有用的函数的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 去掉viewstate保持在页面中的一大
- 下一篇: Editplus For Python[