Tkinter/threading issue

Jerrad Genson jerradgenson at gmail.com
Sun Aug 15 22:55:49 CEST 2010


class MessageServer:
    '''Creates a message server object that listens for textual
information
       and sends it back to the main program. Intended to be spawned
as a
       separate process.
       '''

    def __init__(self, port_number, server_send, server_receive):
        '''@param server_send The pipe MessageServer uses to send text
back to the main program.
           @param port_number The port the server listens on the
network at.
           '''

        self.server_send = server_send
        self.server_receive = server_receive
        self.client_socket = None
        self.address = None

        self.error_logger =
errorlogger.ErrorLogger(program_name=PROGRAM_NAME)

        self.server_socket = socket.socket(socket.AF_INET,
socket.SOCK_STREAM)
        self.server_socket.bind(('localhost', port_number))
        self.server_socket.listen(1)

        self.listen()

    def listen(self):
        # listen for messages until process is killed
        # if a message is received, send it back to the main program
        (self.client_socket, self.address) =
self.server_socket.accept()
        while True:
            input_stream = str(self.client_socket.recv(1024))
            if len(input_stream) != 0:
                os.write(self.server_send, input_stream)
                input_stream = None



More information about the Python-list mailing list