[Tutor] python sockets
Jon Engle
jon.engle at gmail.com
Tue Jun 10 01:33:09 CEST 2014
I am trying to open ports 1025-65535 with the following code (Mostly found
online with small modifications). I am unable to "bind" anything other than
the one port which is selected as input. What am I missing and how do I
bind all the ports simultaneously?
#!/usr/bin/python # This is server.py file
from socket import * #import the socket library
import thread #import the thread library
startingPort=input("\nPlease enter starting port: ")
startingPort=int(startingPort)
def setup():
##let's set up some constants
HOST = '' #we are the host
PORT = startingPort #arbitrary port not currently in use
ADDR = (HOST,PORT) #we need a tuple for the address
BUFSIZE = 4096 #reasonably sized buffer for data
## now we create a new socket object (serv)
## see the python docs for more information on the socket types/flags
serv = socket( AF_INET,SOCK_STREAM)
##bind our socket to the address
serv.bind((ADDR)) #the double parens are to create a tuple with one
element
serv.listen(5) #5 is the maximum number of queued connections we'll allow
serv = socket( AF_INET,SOCK_STREAM)
##bind our socket to the address
serv.bind((ADDR)) #the double parens are to create a tuple with one
element
serv.listen(5) #5 is the maximum number of queued connections we'll allow
print 'listening...'
PORT=PORT+1
conn,addr = serv.accept() #accept the connection
print '...connected!'
conn.send('TEST')
conn.close()
while startingPort<65535:
thread.start_new_thread(setup())
startingPort=startingPort+1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140609/cd483535/attachment.html>
More information about the Tutor
mailing list