OSError:[WinError 10022] socket.listen2中提供了无效的参数

问题描述

我正在服务器项目的Visual Studio代码上运行此服务器代码:

import socket
from _thread import *
import sys

server = "192.168.0.4"
port = 5555

s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)

try:
    s.bind((server,port))

except socket.error as e:
    str(e)

s.listen(2)

print("Waiting for connections...")
print("Server Started!")

def threaded_client(conn):
    conn.send(str.encode("Connected"))
    reply = ""
    while True:
        try:
            data = conn.recv(2048)
            reply = data.decode("utf-8")

            if not data:
                print("Disconnected!")
                break

            else:
                print("Received: ",reply)
                print("Sending: ",reply)

            conn.sendall(str.encode(reply))

        except:
            break

        print("Lost Connection!")
        conn.close()

while True:
    conn,addr = s.accept()
    print("Connected to: ",addr)

    start_new_thread(threaded_client,(conn,))

由于某种原因,我遇到这样的错误:

Traceback (most recent call last):
  File "c:/Users/sande/Desktop/Vihaan/ThirdPartySoftware/Python/VisualStudiosCode/RPSOnline/server.py",line 16,in <module>
    s.listen(2)
OSError: [WinError 10022] An invalid argument was supplied

请帮助我说明为什么会这样。我尝试重新编写代码,但是没有用。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)