sockets and servers

Paul Clinch pclinch at internet-glue.co.uk
Tue Oct 28 15:37:18 EST 2003


guy.flowers at Machineworks.com (Guy) wrote in message news:<f3ff61d9.0310280719.67dea4d9 at posting.google.com>...
> Hi
> 
> Below, code that I found in a book. Server that you can open a telnet
> session to.
> I don't fully understand this code, but I have used it as it provided
> an exstremly good way of creating what I wanted.
> The trouble I'm having at the moment is that I can't find a way to
> access any var in the uc_handler class (example guy)
> or run functions under that class, I would like to run a function from
> below the asyncore.poll(SERVER_TIMEOUT) line
> example the guy function. The code I've provided is just an example,
> my code is a lot longer than this and will take ages to exsplain.
> I understand that each user must have a differnt instance of the
> class, but I can't find out how to access from here,
> or even if this is possible.

I'm not sure what you're trying to do. I'll assume you want to run function guy 
when the server gets the terminator, '\n' in the example. The self parameter 
references all the instances data and functions.

  def found_terminator(self):
      data = self.buffer.upper()
      if data == '':
          print "Disconnect:", self.addr
          sys.stdout.flush()
          self.close()
          return
      self.buffer = ''
      self.push(data + '\r\n')
      self.guy()


Regards, Paul Clinch




More information about the Python-list mailing list