Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

problem with ThreadingTCPServer Handler

24 views
Skip to first unread message

jorge

unread,
Oct 23, 2012, 10:36:00 AM10/23/12
to pytho...@python.org
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

Miki Tebeka

unread,
Oct 23, 2012, 4:51:41 PM10/23/12
to pytho...@python.org
According to the docs (http://docs.python.org/library/socketserver.html#requesthandler-objects) there's self.server available.

Miki Tebeka

unread,
Oct 23, 2012, 4:51:41 PM10/23/12
to comp.lan...@googlegroups.com, pytho...@python.org
0 new messages