So, I'm currently trying to make a small chat client using the server and some clients. I found the code on the Internet, and I wanted to use it as the basis for creating my own. The problem that I am facing now is that it was written in Python 2.x and I am using 3.x. There was nothing to convert, but I ran into some problems in which the program uses sys.stdin.
Source code can be found here .
Here is my code: `
import sys, socket, select
def chat_client():
host = 'localhost'
port = 9009
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(2)
try :
s.connect((host, port))
except :
print('Unable to connect')
sys.exit()
print('Connected to remote host. You can start sending messages')
sys.stdout.write('[Me] '); sys.stdout.flush()
while 1:
socket_list = [sys.stdin, s]
read_sockets, write_sockets, error_sockets = select.select(socket_list , [], [])
for sock in read_sockets:
if sock == s:
data = sock.recv(4096)
if not data :
print('\nDisconnected from chat server')
sys.exit()
else :
sys.stdout.write(data)
sys.stdout.write('[Me] '); sys.stdout.flush()
else :
msg = sys.stdin.readline()
s.send(msg)
sys.stdout.write('[Me] '); sys.stdout.flush()
if __name__ == "__main__":
chat_client()
`
The error I am getting is:
`[Me] Traceback (most recent call last):
File "client.py", line 46, in <module>
chat_client()
File "client.py", line 25, in chat_client
read_sockets, write_sockets, error_sockets = select.select(socket_list , [],
[])
OSError: [WinError 10038] An operation was attempted on something that is not a
socket`
, , , , - , , , . , sys.stdin.
`socket_list = [sys.stdin, s]
read_sockets, write_sockets, error_sockets = select.select(socket_list , [], [])`
, , . , :)