<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Hans-Peter Jansen schreef:
<blockquote cite="mid:200911231605.08218.hpj@urpla.net" type="cite">
<pre wrap="">On Monday 23 November 2009, 15:19:06 Nick Gaens wrote:
</pre>
<blockquote type="cite">
<pre wrap=""> Hans-Peter Jansen schreef:
</pre>
</blockquote>
<pre wrap=""><!---->[...]
</pre>
<blockquote type="cite">
<pre wrap=""> ----------------------------
def __init__(self):
self.server = QtNetwork.QTcpServer(self)
self.server.serverPort = 55555
self.server.newConnection.connect(self.clientConnecting)
self.server.listen() # defaults to QHostAddress.Any
def clientConnecting(self): # used by the "server"
if self.server.hasPendingConnections():
connectingClient = self.server.nextPendingConnection()
connectingClient.readyRead.connect(self.receiveData)
def connectToClient(self, ip): # used by the "client"
socket = QtNetwork.QTcpSocket()
socket.readyRead.connect(self.receiveData)
socket.connectToHost(QtNetwork.QHostAddress(ip), 55555) # ip of
server if socket.waitForConnected(5000):
print "Connected!"
----------------------------
</pre>
</blockquote>
<pre wrap=""><!---->[...]
</pre>
<blockquote type="cite">
<pre wrap=""> How odd that I receive this mail *the moment* my code started working
:-P.
I found that the serverPort may not be overwritten.
I removed this assignment:
self.server.serverPort = 55555
</pre>
</blockquote>
<pre wrap=""><!---->
Assigning properties this way usually won't work in PyQt (although Phil
tackles this already).
try this:
self.server.listen(QtNetwork.QHostAddress.Any, 55555)
</pre>
<blockquote type="cite">
<pre wrap=""> and the clients now can connect to the server w/o any problem.. Downside
is that the port is random..
</pre>
</blockquote>
<pre wrap=""><!---->
Pete
_______________________________________________
PyQt mailing list <a class="moz-txt-link-abbreviated" href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a>
<a class="moz-txt-link-freetext" href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt">http://www.riverbankcomputing.com/mailman/listinfo/pyqt</a>
</pre>
</blockquote>
Hmm.. That doesn't seem to work :-S..<br>
<br>
self.server.listen(QtNetwork.QHostAddress.Any, 55555):<br>
TypeError: argument 1 of QTcpServer.listen() has an invalid type<br>
<br>
How can this be? I've got PyQt4.6.2 on WinXP, Python 2.6.4<br>
</body>
</html>