sockets - Python sock chat client - Problems with select.select() and sys.stdin -


So I'm trying to create a small chat client using a server and a few clients. I got some code online and I wanted to use it as a base to make it my own. Now the problem is facing that it was written in Python 2.x and I'm using 3.x . There was not really much to convert, but I had some problems where the use of the program is sys.stdin .

The original code can be found.

Here is my code: `

  select import system, socket, DIIF Chat_client (): host = 'localhost' port = 9009 s = socket.socket ( Socket.AF_INET, socket.SOCK_STREAM) .settimeout (2) # Connect to remote host: except s.connect (host, port)): print ('unable to connect)' sys.exit () print ('Connect to remote host. You can start sending messages') Sys.stdout.write ('[m]'); 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: # Message from incoming remote server, s data = sock.recv (4096) if the data is not: print ('\ n disconnected from chat servers') sys.exit () and: #print data sys.stdout.write (data) ) Sys.stdout write me] '); Sys.stdout.flush () Other: # User has entered a message msg = sys.stdin.readline () s.send (msg) sys.stdout.write ('[m]'); Sys.stdout.flush () if __name__ == "__main__": chat_client ()  

`

The error I am getting is:

`[m] tracebacks (last call final): file" client.py ", line 46, & lt; Module & gt; Chat_client () file "client.py", line 25, chat_client read_sockets, write_sockets, error_sockets = select.select (socket_list, [], []) OSError: [WinError 10038] An operation was attempted on one of the sockets `

I am getting this error clearly because there is no input of any kind, but since I was unable to find any documents, I could understand that below What is happening in the given lines, I have a tough time fixing it. I do not know what type of input it should have met through sys.stdin .

  `socket_list = [sys.stdin, s] read_sockets, write_sockets, error_sockets Sorry, if I have not been adequately clarified on my problem, answer me and whatever I I'll also provide it to you. Thank you for helping me :)  

WinError Suggestion that you are on Windows. sys.stdin can be considered as a socket on the NIX platform, but not on Windows.

See:

Note that on Windows, this only works for sockets; On other operating systems, it also works for other file types (especially, on UNIX, it works on pipes).

A quick search shows that people select on the socket on a thread and block local I / O on the second thread, but on that Tell me the best or the only way. The framework of the twinkle resonance probably has already solved it.


Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -