<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/3.28.3">
</HEAD>
<BODY>
<BR>
&nbsp;&nbsp;&nbsp; Thanks, that's a good idea, and I've tried it, but still no luck.<BR>
<BR>
&nbsp;&nbsp;&nbsp; Its very strange, I've added some debugging code, so on the client side it looks like this:<BR>
<BR>
if self.socket.waitForConnected(5000):<BR>
&nbsp;&nbsp; print &quot;client: writing&quot;<BR>
&nbsp;&nbsp; self.socket.write(data)<BR>
&nbsp;&nbsp; print &quot;client: sent&quot;<BR>
<BR>
<BR>
&nbsp;&nbsp;&nbsp; And the server side looks like:<BR>
...<BR>
self.socket.newConnection.connect(self.processConnection)<BR>
...<BR>
def processConnection(self):<BR>
&nbsp;&nbsp; print &quot;server: connected&quot;<BR>
&nbsp;&nbsp; clientConnection = self.socket.nextPendingConnection()<BR>
&nbsp;&nbsp; clientConnection.disconnected.connect(clientConnection.deleteLater)<BR>
&nbsp;&nbsp; print &quot;server: socket state:&quot;,<BR>
&nbsp;&nbsp; print clientConnection.state()<BR>
&nbsp;&nbsp; if not clientConnection.waitForReadyRead(CLIENT_NO_REPLY_WAIT):<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if self.DEBUG:<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;WARNING [server] Timeout waiting for client to transmit data&quot;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; clientConnection.disconnectFromHost()<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return<BR>
<BR>
etc.<BR>
<BR>
<BR>
And the output looks like:<BR>
<BR>
client: writing<BR>
client: sent<BR>
server: connected<BR>
server: socket state: 3<BR>
WARNING [server] Timeout waiting for client to transmit data<BR>
<BR>
<BR>
...so what's happening is the client is waiting for the connection to establish and then writing immediately, but the server hasn't even begun processing that the connection has been made yet. Then the server is timing out waiting for the packet of information which has already flown past.<BR>
<BR>
<BR>
&nbsp;&nbsp;&nbsp; Yet again this all works perfectly fine when run as two separate programs.<BR>
<BR>
<BR>
Cheers<BR>
<BR>
Steve<BR>
<BR>
<BR>
On Wed, 2010-07-07 at 20:21 +0200, mille kink wrote:<BR>
<BLOCKQUOTE TYPE=CITE>
    Perhaps you could try to insert the 'local server' into a sperate thread.<BR>
    <BR>
    Kind regard,<BR>
    Ronny<BR>
    <BR>
    <BLOCKQUOTE TYPE=CITE>
        On 7 Jul 2010 15:09, &quot;Steve Castellotti&quot; &lt;<A HREF="mailto:sc@puzzlebox.info">sc@puzzlebox.info</A>&gt; wrote:<BR>
        <BR>
        Hello all-<BR>
        <BR>
        &nbsp;&nbsp;&nbsp; I have created two application classes using PyQt, one a server which normally runs in console mode, the other a client with complete GUI. The server opens a socket and listens for connections from the client which issue various commands to be carried out. These are bother working quite well.<BR>
        <BR>
        &nbsp;&nbsp;&nbsp; I would like to produce a third script which launches bother the server and client processes at the same time, with all communication happening over localhost. The point is to allow the user to run the &quot;network&quot; version of the interface (connecting to the separate server process over the network) or a &quot;local&quot; version which is self-contained (including the server), while reusing the same code as much as possible.<BR>
        <BR>
        &nbsp;&nbsp;&nbsp; This last piece is nearly working, however the server component in the third &quot;local&quot; script is timing out during the communication process. I am wondering if I am simply failing to properly initialize the two class instances in order to share the single event loop.<BR>
        <BR>
        <BR>
        When launching the client application in &quot;network&quot; mode, the code looks something like this:<BR>
        <BR>
        app = QtGui.QApplication(sys.argv)<BR>
        window = client_interface(log)<BR>
        window.show()<BR>
        sys.exit(app.exec_())<BR>
        <BR>
        <BR>
        When launching the server application from the console for &quot;network&quot; mode, the code looks like this:<BR>
        <BR>
        # Perform KeyboardInterrupt handling<BR>
        signal.signal(signal.SIGINT, signal.SIG_DFL)<BR>
        app = QtCore.QCoreApplication(sys.argv)<BR>
        server = network_server(log, server_interface, server_port)<BR>
        sys.exit(app.exec_())<BR>
        <BR>
        <BR>
        And when trying to launch both in the same event loop for the &quot;local&quot; third script, I'm doing:<BR>
        <BR>
        app = QtGui.QApplication(sys.argv)<BR>
        server = server.network_server(log, server_interface, server_port)<BR>
        window = client.client_interface(log)<BR>
        window.show()<BR>
        sys.exit(app.exec_())<BR>
        <BR>
        <BR>
        <BR>
        In the server code, process control happens something like this:<BR>
        <BR>
        ...<BR>
        self.socket.newConnection.connect(self.processConnection)<BR>
        ...<BR>
        def processConnection(self):<BR>
        &nbsp;&nbsp; clientConnection = self.socket.nextPendingConnection()<BR>
        &nbsp;&nbsp; if not clientConnection.waitForReadyRead(5000):<BR>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;Timeout waiting for client to transmit data&quot;<BR>
        ...<BR>
        etc.<BR>
        <BR>
        <BR>
        &nbsp;&nbsp;&nbsp; Currently each time the client goes to send data to the server, the connection seems to establish and the client side reports writing to the socket, but the server side times out after five seconds without the data packet having been received. The client GUI interacts properly, and the server routines seem to be getting called properly.<BR>
        <BR>
        &nbsp;&nbsp;&nbsp; The odd thing is I can start up the &quot;local&quot; integrated script, which will launch the server process (opening and listening to the port) as well as the client GUI, then connecting that server process by launching an instances of the &quot;network&quot; mode client GUI (so now there's two GUIs on the screen), and everything works fine with the second GUI. So it would seem the server side of the &quot;local&quot; script is working just fine.<BR>
        <BR>
        <BR>
        &nbsp;&nbsp;&nbsp; Can anyone offer me pointers regards what I might be doing wrong, or perhaps where to look next?<BR>
        <BR>
        <BR>
        Cheers<BR>
        &nbsp;&nbsp;&nbsp; <BR>
        Steve Castellotti<BR>
        <BR>
        <BR>
        <BR>
        <BR>
        _______________________________________________<BR>
        PyQt mailing list &nbsp; &nbsp;<A HREF="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</A><BR>
        <A HREF="http://www.riverbankcomputing.com/mailman/listinfo/pyqt">http://www.riverbankcomputing.com/mailman/listinfo/pyqt</A><BR>
    </BLOCKQUOTE>
    <BR>
</BLOCKQUOTE>
<BR>
</BODY>
</HTML>