python - 异步套接字,本地主机与本地 IP
问题描述
我正在编写一个 Asyncio 脚本。一切正常,但我对我在元组 asyncio 返回的地址中看到的内容有疑问。
这行代码根据我使用 localhost 或本地 IP 地址与客户端连接的天气返回两个不同的内容。
(Server code)
addr = writer.get_extra_info('peername')
print("Received %r from %r" % (message, addr))
使用 localhost 作为我在客户端中的连接,我在我的服务器上看到了这个
(Client code)
reader, writer = await asyncio.open_connection('localhost', 8888, loop=asyncloop)
(Server prints)
Received 'Hello World!' from ('::1', 50402, 0, 0)
并在我的客户端中使用 IP 地址作为我的连接,
(Client code)
reader, writer = await asyncio.open_connection('192.168.147.200', 8888, loop=asyncloop)
(Server prints)
Received 'Hello World!' from ('192.168.147.139', 50313)
第一个元组中的两个零是什么意思?为什么当我连接 IP 时它们不在那里?
解决方案
其他字段似乎与IPv6 地址范围有关。
推荐阅读
- ios - 一些闹钟应用程序如何播放超过 30 秒的音频?
- java - Spring Boot:像线程这样的可扩展任务 - 怎么办?
- mongodb - 如何改进此搜索查询?
- java - 从 1 到 100 的随机数并打印第一个输入参数号
- reactjs - 具有 React Native + Firebase 存储的照片应用程序的最佳实践
- cypress - Cypress:捕获所有 XHR 请求并将其记录到文件中
- r - 逐列比较的高效矩阵结构
- javascript - Discord Bot 发送多条消息,但我只希望它发送一条
- python - 对具有列表字符串数据的 pandas 列进行元素明智搜索
- pyodbc - pyodbc upsert 错误 - SQL 包含 0 个参数标记,但提供了 3 个参数','HY000'