<!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>
Thanks, that's a good idea, and I've tried it, but still no luck.<BR>
<BR>
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>
print "client: writing"<BR>
self.socket.write(data)<BR>
print "client: sent"<BR>
<BR>
<BR>
And the server side looks like:<BR>
...<BR>
self.socket.newConnection.connect(self.processConnection)<BR>
...<BR>
def processConnection(self):<BR>
print "server: connected"<BR>
clientConnection = self.socket.nextPendingConnection()<BR>
clientConnection.disconnected.connect(clientConnection.deleteLater)<BR>
print "server: socket state:",<BR>
print clientConnection.state()<BR>
if not clientConnection.waitForReadyRead(CLIENT_NO_REPLY_WAIT):<BR>
if self.DEBUG:<BR>
print "WARNING [server] Timeout waiting for client to transmit data"<BR>
clientConnection.disconnectFromHost()<BR>
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>
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, "Steve Castellotti" <<A HREF="mailto:sc@puzzlebox.info">sc@puzzlebox.info</A>> wrote:<BR>
<BR>
Hello all-<BR>
<BR>
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>
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 "network" version of the interface (connecting to the separate server process over the network) or a "local" version which is self-contained (including the server), while reusing the same code as much as possible.<BR>
<BR>
This last piece is nearly working, however the server component in the third "local" 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 "network" 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 "network" 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 "local" 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>
clientConnection = self.socket.nextPendingConnection()<BR>
if not clientConnection.waitForReadyRead(5000):<BR>
print "Timeout waiting for client to transmit data"<BR>
...<BR>
etc.<BR>
<BR>
<BR>
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>
The odd thing is I can start up the "local" 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 "network" 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 "local" script is working just fine.<BR>
<BR>
<BR>
Can anyone offer me pointers regards what I might be doing wrong, or perhaps where to look next?<BR>
<BR>
<BR>
Cheers<BR>
<BR>
Steve Castellotti<BR>
<BR>
<BR>
<BR>
<BR>
_______________________________________________<BR>
PyQt mailing list <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>