PDA

View Full Version : another server example, or, please help me


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,))

bestworldweb
11-24-2002, 06:06 AM
Err sorry about the spelling and grammer errors, my fonts in Konqueror dont work well on Code Froum and makes it hard to proof read

jemfinch
11-24-2002, 06:47 AM
Did you read my post in the other thread?

Go to http://www.nightmare.com/medusa/ . Read the tutorial. Learn about asynchronous network programming. Perhaps try http://www.twistedmatrix.com/ if you're feeling adventurous. But above all else, go to the trouble to actually learn things on your own. Asking people to spoonfeed you all the time just isn't a solution.

Jeremy

inkedmn
11-24-2002, 08:08 PM
oh, and FYI, put your code in [ code ] tags so it's better formatted :)