聊天室应用程序,python抛出以下异常:OSError:[WinError 10038]尝试对非套接字的操作

时间:2018-06-10 17:38:58

标签: python multithreading sockets exception networking

我已尝试过所有变体,但此异常只是不断弹出。关于这个例外可以做些什么?

这是我的客户端代码:

# Client side script for the chat room
import socket
import select
import sys

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

if len(sys.argv) != 3:
    print("Correct usage: script, IP address, port number")
    exit()

IP_address = str(sys.argv[1])
Port = int(sys.argv[2])

server.connect((IP_address, Port))

while True:
    # Maintaining a possible list of input streams
    socket_list = [sys.stdin, server]

    read_sockets, write_sockets, error_socket = select.select(socket_list, [], [])

    for socks in read_sockets:
        if socks == server:
            message = socks.recv(2048)
            print(message)
        else:
            message = sys.stdin.readline()
            server.send(message)
            sys.stdout.write("<You>")
            sys.stdout.write(message)
            sys.stdout.flush()

server.close()

运行此代码时抛出的异常如下:

Traceback (most recent call last):
File "ClientSideScript.py", line 21, in <module>
read_sockets, write_sockets, error_socket = select.select(socket_list, [], [])
OSError: [WinError 10038] An operation was attempted on something that is not a socket

我也尝试在while循环中加入“server.close()”,但它仍无效。

0 个答案:

没有答案