Title: Problems using gtk.input_add() with sockets on Windows 2000

Hi,

I'm having problems getting callbacks registered with gtk.input_add() working, when using sockets on a Windows 2000 machine. I've written a test driver that can successfully create a listener socket, handle a new connection and receive data from the connection. I've also got a test driver that gets callbacks registered with stk.input_add() to work successfully. But I can't get the two together working.

I've checked the FAQ and the mail archives for any messages about problems with input_add() on win32. The concensus seems to be that it works fine. Maybe I'm just doing something wrong. :(

By the way, I'm using an old version of PyGTK. I don't know exactly which version it is because it comes packaged with an application called OpenEV that I'm trying to augment, but I'm pretty sure its GTK 0.6.x. I have no option to upgrade this because my code changes will need to work with future versions of the OpenEV distribution, which I have no control over.

Here's some code that shows gtk.input_add() working:

<<CUT HERE>>

import gtk
import GDK

def foo(a, b):
    print "foo called with args:", a, b
    return True

gtk.input_add(0, GDK.INPUT_READ, foo)
gtk.mainloop()

<<CUT HERE>>


Here's my test driver I'm trying to get working. Can someone please tell me what I'm doing wrong? Thanks!

James


<<CUT HERE = testdriver_server>>

import socket
import gtk
import GDK

class Test:
    def __init__(self):
        self.file = open("C:\\temp\\testdriver.log", 'w')
        HOST = ''                 # Symbolic name meaning the local host
        PORT = 5123               # Arbitrary non-privileged port
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        sock.bind((HOST, PORT))
        self.listenForConnection(sock)
        self.file.write("Listening on connection %s:%d\n" % (HOST, PORT))

##        # XXX Start TEST
##        conn, addr = sock.accept()
##        self.readFromConnection(conn, 0)
##
##        conn, addr = sock.accept()
##        self.readFromConnection(conn, 0)
##
##        conn, addr = sock.accept()
##        self.readFromConnection(conn, 0)
##
##        conn, addr = sock.accept()
##        self.readFromConnection(conn, 0)
##        # XXX End TEST

        print sock.fileno()
        self.id = gtk.input_add(sock.fileno(), GDK.INPUT_READ, self.handleNewConnection)

        # Create a small window to quit
        self.window = gtk.GtkWindow(gtk.WINDOW_TOPLEVEL)
        self.window.connect("destroy", self.destroy)
        self.window.set_border_width(10)

        self.button = gtk.GtkButton("Stop Test Driver")
        self.button.connect("clicked", self.destroy)
        self.window.add(self.button)

    def run(self):
        self.button.show()
        self.window.show_all()
        gtk.mainloop()

    def listenForConnection(self, sock):
        sock.listen(5)

    def handleNewConnection(self, sock, cond):
        print "handleNewConnection"
        self.file.write("handleNewConnection\n")
        conn, addr = sock.accept()
        print "Accepted connection"
        self.file.write("Accepted connection\n")
        ia = gtk.input_add(conn, GDK.INPUT_READ, self.readFromConnection)
        self.listenForConnection(sock)
        return True

    def readFromConnection(self, conn, cond):
        print "readFromConnection"
        self.file.write("readFromConnection\n")
        # XXX Should loop here on receive to make sure we get all the data
        while 1:
            data = "">
            if not data or data == "quit":
                conn.close()
                return False

            print data
            self.file.write("%s\n" % data)
        return True

    def destroy(self, *args):
        """ Callback function that is activated when the program is destoyed
        """
        self.window.hide()
        gtk.mainquit()


def main():
    testdriver = Test()
    testdriver.run()

if __name__ == '__main__':
    main()

<<CUT HERE = testdriver_server>>


<<CUT HERE = testdriver_client>>

import socket

HOST = '127.0.0.1'      # The local host?
PORT = 5123             # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
s.send('Hello, world')
s.close()

<<CUT HERE = testdriver_client>>
__________________________________________________

James Rowe
Software Engineer
MDA
13800 Commerce Parkway
Richmond, B.C., Canada V6V 2J3

[EMAIL PROTECTED] .com
__________________________________________________

This e-mail and any attachments are intended solely for the use of the intended recipient(s) and may contain legally privileged, proprietary and/or confidential information.  Any use, disclosure, dissemination, distribution or copying of this e-mail and any attachments for any purposes that have not been specifically authorized by the sender is strictly prohibited.  If you are not the intended recipient, please immediately notify the sender by reply e-mail and permanently delete all copies and attachments.

The entire content of this e-mail is for "information purposes" only and should not be relied upon by the recipient in any way unless otherwise confirmed in writing by way of letter or facsimile.

_______________________________________________
pygtk mailing list   [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to