从我的小型Python套接字程序中获取错误。返回“OSError:[WinError 10022]提供了无效的参数”

时间:2016-04-20 10:51:02

标签: python sockets python-3.x client-server

我正在学习使用Python套接字的教程:客户端服务器here。我已经研究过类似的问题,但是其他人只是出现拼写错误,而不是。期待找到解决方案!

import socket
import sys
from _thread import *

host = ''
port = 5555
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)


try:
    s.bind((host, port))
except socket.error as e:
    print(str(e))

s.listen(5)

def threaded_client(conn):
    conn.send(str.encode('Welcome, type your info \n'))

    while True:
        data = conn.recv(2048)
        reply = 'Server output: '+data.decode('utf-8')
        if not data:
            break
        conn.sendall(str.encode(reply))

    conn.close()

while True:
    conn, addr = s.accept()
    print('connected to: '+addr[0]+':'+str(addr[1]))        

    start_new_thread(threaded_client, (conn,))

提前致谢:)

1 个答案:

答案 0 :(得分:0)

您的程序在我的计算机上正常运行:

enter image description here