日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

python网络编程-一些常用有用的函数

發(fā)布時(shí)間:2025/3/15 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python网络编程-一些常用有用的函数 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
socket.getservbyname(servicename[, protocolname]) –> integer

查詢某個(gè)協(xié)議對(duì)應(yīng)的端口號(hào),需要使用兩個(gè)參數(shù),servicename對(duì)應(yī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
  • 與查詢地址信息有關(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)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。