日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

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

發布時間:2025/3/15 python 12 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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网络编程-一些常用有用的函数的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。