2:
string = string[0:-2]
else:
string = ' '
else:
string = False
return string
# a listen thread,listen remote connect
# when a remote machine request to connect,it will create a read thread to handle
class Listener(threading.Thread):
def __init__(self,port):
threading.Thread.__init__(self)
self.port = port
self.sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
self.sock.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
self.sock.bind(("0.0.0.0",port))
self.sock.listen(0)
def run(self):
print "listener started"
while True:
client,cltadd = self.sock.accept()
print "accept a connect..."
Reader(client).start()
cltadd = cltadd
print "accept a connect(new reader..)"
lst = Listener(8888) # create a listen thread
lst.start() # then start
# Now,you can use telnet to test it,the command is "telnet 127.0.0.1 9011"
# You also can use web broswer to test,input the address of "http://127.0.0.1:9011" and press Enter button
# Enjoy it....