首页 > 解决方案 > 不明白为什么服务器不会响应客户端(即使在打开防火墙后 | 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)

标签: python-3.xpython-2.7socketsserverclient-server

解决方案


推荐阅读