python - 在python中连接服务器和客户端时出现超时错误
问题描述
我在服务器端使用了这个:
import socket
mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mysock.bind((socket.gethostname(),9999))
mysock.listen(1)
while True:
clt, addr = mysock.accept()
print('Connection request from', addr, 'was successfully established')
clt.send('Connected to XYZ'.encode())
clt.send('Closing connection, byee'.encode())
clt.close()
这在客户端:
import socket
mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mysock.connect(("my ip",9999)) #will put ip of server
while True:
msg = mysock.recv(1024)
if len(msg) < 1:
break
mystring = msg.decode()
print(mystring)
在这里,当客户端脚本运行时,它会产生以下错误:
PS C:\Users\91829\Blogo> & C:/Users/91829/AppData/Local/Programs/Python/Python37/python.exe c:/Users/91829/Desktop/uu.py
Traceback (most recent call last):
File "c:/Users/91829/Desktop/uu.py", line 4, in <module>
mysock.connect(("my ip",9999))
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
PS C:\Users\91829\Blogo>
注意:在此服务器和主机是不同的机器。服务器是本地主机,即我的机器,客户端是我朋友的机器
谢谢你的帮助。
解决方案
推荐阅读
- c++ - 为什么在返回 unordered_map 值时需要声明默认构造函数才能编译?
- android - 在 Kotlin 中生成 HMAC-SHA1 签名
- c# - 指数超出范围。必须为非负数且小于集合的大小... 参数名称:index"
- java - 使 ViewPager 的高度等于 PagerAdapter 中的最高项
- json - 如何使用 VB.net 使用 Json 补丁文件
- loops - 仅从下面的单元格插入行并复制公式
- c++ - “运算符类()”类型的运算符如何工作
- ansible - 如何在使用串行时结束整个播放(Ansible 2.9)
- javascript - 将对象数组复杂转换为另一个数组
- python - 如何重塑 Tensorflow 数据集中的数据?