Hi,
I've written this code, the general idea was to listen on all 65535
port of tcp for connection.
"""
#!/usr/bin/env python
import socket, select
def get_non_blockin g_socket(port_n umber):
s = socket.socket(s ocket.AF_INET, socket.SOCK_STR EAM)
s.setblocking(0 )
s.bind(('0.0.0. 0', port_number))
s.listen(1)
return s
all_sockets = map(get_non_blo cking_socket, xrange(10000, 15000))
while 1:
ready_to_read, ready_to_write, in_error =
select.select(a ll_sockets, [], [], 0)
for nb_active_socke t in all_sockets:
if nb_active_socke t in ready_to_read:
conn, addr = nb_active_socke t.accept()
while 1:
data = conn.recv(1024)
if not data: break
conn.send(data)
conn.close()
"""
The thing is that when I tried to run this at first I got
"""
python non_blocking_ra nge.py
Traceback (most recent call last):
File "non_blocking_r ange.py", line 12, in ?
all_sockets = map(get_non_blo cking_socket, xrange(10000, 15000))
File "non_blocking_r ange.py", line 6, in get_non_blockin g_socket
s = socket.socket(s ocket.AF_INET, socket.SOCK_STR EAM)
File "/usr/lib/python2.4/socket.py", line 148, in __init__
_sock = _realsocket(fam ily, type, proto)
socket.error: (24, 'Too many open files')
"""
So I set ulimit -n 500000, now I'm getting
"""
python non_blocking_ra nge.py
Traceback (most recent call last):
File "non_blocking_r ange.py", line 15, in ?
ready_to_read, ready_to_write, in_error =
select.select(a ll_sockets, [], [], 0)
ValueError: filedescriptor out of range in select()
"""
Should I be using a different version of select or something? Or
should I implement this the other way around, if so please suggest
how.
Thank you very much,
(enthusiastical ly learning python) Maxim.
--
Cheers,
Maxim Veksler
"Free as in Freedom" - Do u GNU ?
I've written this code, the general idea was to listen on all 65535
port of tcp for connection.
"""
#!/usr/bin/env python
import socket, select
def get_non_blockin g_socket(port_n umber):
s = socket.socket(s ocket.AF_INET, socket.SOCK_STR EAM)
s.setblocking(0 )
s.bind(('0.0.0. 0', port_number))
s.listen(1)
return s
all_sockets = map(get_non_blo cking_socket, xrange(10000, 15000))
while 1:
ready_to_read, ready_to_write, in_error =
select.select(a ll_sockets, [], [], 0)
for nb_active_socke t in all_sockets:
if nb_active_socke t in ready_to_read:
conn, addr = nb_active_socke t.accept()
while 1:
data = conn.recv(1024)
if not data: break
conn.send(data)
conn.close()
"""
The thing is that when I tried to run this at first I got
"""
python non_blocking_ra nge.py
Traceback (most recent call last):
File "non_blocking_r ange.py", line 12, in ?
all_sockets = map(get_non_blo cking_socket, xrange(10000, 15000))
File "non_blocking_r ange.py", line 6, in get_non_blockin g_socket
s = socket.socket(s ocket.AF_INET, socket.SOCK_STR EAM)
File "/usr/lib/python2.4/socket.py", line 148, in __init__
_sock = _realsocket(fam ily, type, proto)
socket.error: (24, 'Too many open files')
"""
So I set ulimit -n 500000, now I'm getting
"""
python non_blocking_ra nge.py
Traceback (most recent call last):
File "non_blocking_r ange.py", line 15, in ?
ready_to_read, ready_to_write, in_error =
select.select(a ll_sockets, [], [], 0)
ValueError: filedescriptor out of range in select()
"""
Should I be using a different version of select or something? Or
should I implement this the other way around, if so please suggest
how.
Thank you very much,
(enthusiastical ly learning python) Maxim.
--
Cheers,
Maxim Veksler
"Free as in Freedom" - Do u GNU ?
Comment