bestworldweb
11-24-2002, 06:03 AM
I posted the following code, but then was convinced that I souldnt use threads to handle multiple connection to the server. I your know how, can you post code that dosnt use threads but does the same. It must use sockets, it can use select()...
my code :
#! /usr/bin/python
import socket,thread,random
def connection(client):
client.send("wassup")
client.close()
return 0
port=random.randrange(2000,3000)
server=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
server.bind(("localhost",port))
server.listen(5)
print "Port :"+str(port)+"\n"
client,address=server.accept()
thread.start_new_thread(connection,(client,))
while 1:
client,address=server.accept()
thread.start_new_thread(connection,(client,))
my code :
#! /usr/bin/python
import socket,thread,random
def connection(client):
client.send("wassup")
client.close()
return 0
port=random.randrange(2000,3000)
server=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
server.bind(("localhost",port))
server.listen(5)
print "Port :"+str(port)+"\n"
client,address=server.accept()
thread.start_new_thread(connection,(client,))
while 1:
client,address=server.accept()
thread.start_new_thread(connection,(client,))