Reputation: 4295
I keep on receiving this error of 1 - 3 arguments needing to be sequences
import socket # Import socket module
import sys
import select
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Create a socket object
host = "127.0.0.1" # Get local machine name
port = 50001 # Reserve a port for your service.
s.bind((host, port)) # Bind to the port
a = []
b = []
s.listen(1) # Now wait for client connection.
c, addr = s.accept() # Establish connection with client.
s.setblocking(0)
ready = select.select(s, s, s, 1) # i believe the error lies in here
while True:
print "reached"
if ready[0]:
print "reached1"
data = mysocket.recv(4096)
print 'Got connection from', addr
c.send('Thank you for connecting \r\n') #all strings have to end with /r/n!!!
print "sent"
c.close() # Close the connection
Error
Select.select arguments 1 - 3 has to be sequences.
I am new to python and hence i am unsure of what the error is. I googled the select code from another post as i wanted my recv socket to be non blocking
Upvotes: 1
Views: 3335
Reputation: 69062
select.select
takes three lists as arguments, rlist
, wlist
and xlist
:
- rlist: wait until ready for reading
- wlist: wait until ready for writing
- xlist: wait for an “exceptional condition” (see the manual page for what your system considers such a condition)
You're not passing lists but single sockets.
Try this:
ready = select.select([s], [s], [s], 1)
The return value will, again, be a tuple of three lists, the first containig sockets ready for reading, the second sockets ready for writing and the third sockets in 'exceptional condition'.
Note also that in your while loop you never update ready
, so you will always use the same lists of sockets. Also, you should have a break
somewhere, otherwise you'll end up calling c.send
in an endless loop.
Upvotes: 4