python-3.x - 不明白为什么服务器不会响应客户端(即使在打开防火墙后 | Python | 服务器
问题描述
我在 MacBook air 上设置了我的服务器,我的客户端从 Windows 10 机器连接。我关闭了两台机器上的所有安全和防火墙(因为当你失去所有希望时,你就会这样做)并尝试多次从我的 Windows 机器连接,但无济于事。顺便说一句,我在同一个网络上(不使用虚拟机)。
错误:
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
服务器:
import socket, threading
import multiprocessing
from time import sleep
# tells us the bytes of the message
HEADER = 64
PORT = 5430
# or you could do socket.gethostbyname(socket.gethostname())
SERVER = socket.gethostbyname(socket.gethostname())
ADDR = (SERVER, PORT)
FORMAT = 'utf-8'
DISCONNECT_MESSAGE = '!END'
# defines the type of connection
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(ADDR)
def start():
server.listen()
print(f'[LISTENING] Server is listening on {SERVER}')
while True:
conn, addr = server.accept()
print('[ACTIVE CONNECTIONS] 1')
start()
客户:
from time import sleep
import socket, subprocess
HEADER = 64
PORT = 5430
FORMAT = 'utf-8'
DISCONNECT_MESSAGE = '!END'
SERVER = '192.32.322.3'
ADDR = (SERVER, PORT)
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(ADDR)
解决方案
推荐阅读
- node.js - Amazon Aws Chime 套接字 IO
- python - 为什么 python-iptables 在使用 syslog 模块时会出现问题
- php - 无法使用 php 非官方 sdk 连接到 firebase 数据库
- mongodb - 如何删除 MongoDB 中的重复项?
- ios - Apple 应用内沙箱收据验证有时会返回空 JSON 响应
- android - Osmdroid 尝试在 Fragment.onStart() 期间重绘已删除的多边形
- java - 如何在 Spring-Boot 项目中为电话号码身份验证创建 REST API?
- amazon-s3 - 如何从 aws javascript sdk 中的 selectObjectContent 获取可读流?
- javascript - antD 模型 API - 背景颜色变化
- python - 如何使用 python 错误在 Google colab 中读取更大的镶木地板文件:ValueError("engine must be one of 'pyarrow', 'fastparquet'")