[PyQt] PyQt4 server trial

Uğur Çetin ugur.jnmbk at gmail.com
Fri May 25 15:22:20 BST 2007


Hi,

I tried to make a simple PyQt4 server that should work without a gui.
But I think I'm missing some points in this, because the codes I wrote
simply doesn't work(any connection is refused). Can you tell me where
the problem is?

content of servertry.py
-----------------------------
from PyQt4 import QtCore, QtNetwork
import sys


class MyServer(QtNetwork.QTcpServer):
    def __init__(self, parent):
        QtNetwork.QTcpServer.__init__(self, parent)
        self.listen(QtNetwork.QHostAddress(QtNetwork.QHostAddress.Any), 23105)
    def incomingConnection(self):
        print "A connection has come!"

app = QtCore.QCoreApplication(sys.argv)
server = MyServer(QtCore.QObject())
sys.exit(app.exec_())

content of clienttry.py
----------------------------
import socket
from PyQt4 import QtNetwork

try:
    mySocket = socket.socket()
    mySocket.connect(("", 23105))
except:
    print "python socket didn't work, trying PyQt4 socket"
    mySocket = QtNetwork.QTcpSocket()
    mySocket.connectToHost(QtNetwork.QHostAddress(QtNetwork.QHostAddress.LocalHost),
23105)
    print "waiting for connection..."
    mySocket.waitForConnected()
    print "connection state is: %d" % mySocket.state()

-- 
Thanks,
Uğur Çetin



More information about the PyQt mailing list