problem with ThreadingTCPServer Handler

jorge jaorozco at estudiantes.uci.cu
Tue Oct 23 10:36:00 EDT 2012


I'm programming a server that most send a message to each client 
connected to it and nothing else. this is obviously a base of what i 
want to do. the thing is, I made a class wich contains the Handler class 
for the ThreadingTCPServer and starts the server but i don't know how 
can i access the message variable contained in the class from the 
Handler since I have not to instance the Handler by myself.
here is the base code of what I'm doing.

import SocketServer
import socket
from threading import Thread

class CustomTCPServer:
     msg = "no message"
     outport = 8080

     class Handler(SocketServer.BaseRequestHandler):
         def handle(self):
             self.request.sendall('<here goes msg from CustomTCPServer>')


     def __init__(self,msg,outport):
         self.msg = server
         self.outport = outport

     def runServer(self):
         addr = ('',self.outport)
         s = SocketServer.ThreadingTCPServer(addr,self.Handler)
         r = Thread(target=s.serve_forever).start()
         print '> Server running running',self.server,self.outport


CustomTCPServer('msg1',1212).runServer()
CustomTCPServer('msg2',1213).runServer()

can anyone please help me?

10mo. ANIVERSARIO DE LA CREACION DE LA UNIVERSIDAD DE LAS CIENCIAS INFORMATICAS...
CONECTADOS AL FUTURO, CONECTADOS A LA REVOLUCION

http://www.uci.cu
http://www.facebook.com/universidad.uci
http://www.flickr.com/photos/universidad_uci



More information about the Python-list mailing list