Passing data into my StreamRequestHandler?

Richard richardd at hmgcc.gov.uk
Tue Jun 3 08:37:58 EDT 2003


Hi,

I have a TCP Server class using SocketServer.TCPServer( ) and a handler
class which inherits from SocketServer.StreamRequestHandler. When an
incoming connection is made, the overridden handle( ) function gets called
which is fine, however can anyone tell me how I go about passing data into
the handler object from my server object?

Here is my code:

import SocketServer

class ConnectionEndpointHandler(SocketServer.StreamRequestHandler):

 def handle(self):
  print "Connected!"

class sServer:

 m_InAddress = []
 m_OutAddress = []

 def __init__(self, inAddress):
  self.m_InAddress = inAddress

 def start(self):
  m_Server = SocketServer.TCPServer((self.m_InAddress[0],
int(self.m_InAddress[1])), ConnectionEndpointHandler)
  m_Server.serve_forever()

Also, as it currently stands (I have another file which just creates an
instance of my sServer, provides the inAddress and calls start( ) ) this
just continually runs, printing 'Connected' every time I make a connection
to it. I know that serve_forever( ) does this, but can anyone tell me how I
interrupt this to exit the program? I am running on Win2K and CTRL-C doesn't
seem to work, meaning I am forced to close down the console window.

TIA

Richard







More information about the Python-list mailing list