Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #31932

problem with ThreadingTCPServer Handler

Date 2012-10-23 10:36 -0400
From jorge <jaorozco@estudiantes.uci.cu>
Subject problem with ThreadingTCPServer Handler
Newsgroups comp.lang.python
Message-ID <mailman.2666.1351003524.27098.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

problem with ThreadingTCPServer Handler jorge <jaorozco@estudiantes.uci.cu> - 2012-10-23 10:36 -0400
  Re: problem with ThreadingTCPServer Handler Miki Tebeka <miki.tebeka@gmail.com> - 2012-10-23 13:51 -0700
  Re: problem with ThreadingTCPServer Handler Miki Tebeka <miki.tebeka@gmail.com> - 2012-10-23 13:51 -0700

csiph-web