Simple Python Echo Server - Wrong Argument
Question: 
    import select
    import socket
    import sys
    
    host = ''
    port = 50000
    backlog = 5
    size = 1024
    server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    server.bind((host,port))
    server.listen(5)
    input = [server,sys.stdin]
    running = 1
    while running:
        inputready,outputready,exceptready = select.select(input,[],[])
    
        for s in inputready:
    
            if s == server:
                # handle the server socket
                client, address = server.accept()
                input.append(client)
    
            elif s == sys.stdin:
                # handle standard input
                junk = sys.stdin.readline()
                running = 0 
    
            else:
                # handle all other sockets
                data = s.recv(size)
                if data:
                    s.send(data)
                else:
                    s.close()
                    input.remove(s)
    server.close()
    

Whenever I run this code, I get this error message for my argument for the
while loop:

    
    
    inputready,outputready,exceptready = select.select(input,[],[])
    TypeError: argument must be an int, or have a fileno() method.
    

How can I fix this to make the server run properly? Sorry if this is a bad
question, I'm new to python and I can't figure this out. Thanks.


Answer: Yeah found the solution to your problem their seem to be `sys.stdin` , the
python IDLE GUI for some reason doesn't allow you to use `sys.stdin.fileno()`
in your code, while if you run it in the command prompt or the terminal it
will work fine on linux. [Link](http://bugs.python.org/issue3003)

An if your using windows, you cant pass the `sys.stdin` as an argument to the
select() function, as in windows it accepts only sockets as arguments. As
Explained in the documentation
[Documentation](http://docs.python.org/2/library/select.html)

> Note: File objects on Windows are not acceptable, but sockets are. On
> Windows, the underlying select() function is provided by the WinSock
> library, and does not handle file descriptors that don’t originate from
> WinSock.

So to mitigate the problem , such that it works on both windows and linux:

    
    
    import select 
    import socket 
    import sys 
    
    host = '' 
    port = 50000 
    backlog = 5 
    size = 1024 
    server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
    server.bind((host,port)) 
    server.listen(backlog) 
    input1 = [server]
    running = 1
    
    
    while running: 
        inputready,outputready,exceptready = select.select(input1,[],[]) 
    
        for s in inputready: 
    
            if s == server: 
                    # handle the server socket 
                    client, address = server.accept()
                    input1.append(client) 
    
            elif s == sys.stdin: 
                # handle standard input 
                junk = sys.stdin.readline() 
                running = 0 
    
            else: 
                # handle all other sockets 
                data = s.recv(size) 
                if data: 
                    s.send(data) 
                else: 
                    s.close() 
                    input1.remove(s) 
    server.close()
    

