Sam George
Sam George

Reputation: 47

OSError: [WinError 10038] An operation was attempted on something that is not a socket (PYTHON3)

can't find a working solution to this problem, so I decided to ask anew.

Error Message:

Traceback (most recent call last): File "C:\New\pythonProject1\client.py", line 15, in read_sockets, write_socket, error_socket = select.select(sockets_list, [], []) OSError: [WinError 10038] An operation was attempted on something that is not a socket

Code Snippet:

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:
    sockets_list = [sys.stdin, server]
    read_sockets, write_socket, error_socket = select.select(sockets_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()

Upvotes: 0

Views: 403

Answers (1)

Mark Tolonen
Mark Tolonen

Reputation: 177554

Unlike *nix, Windows sockets are not compatible with file descriptors. You can’t use sys.stdin with select.

Upvotes: 1

Related Questions