[PyQt] socket problem
Hans-Peter Jansen
hpj at urpla.net
Thu Dec 3 10:25:16 GMT 2009
On Thursday 03 December 2009, 10:19:38 Prashant Saxena wrote:
> Here are the two version of my Receiver & Sender scripts:
> Receiver
> if status:
>
> # Create socket
> self.socket = QtNetwork.QUdpSocket(self)
> self.socket.setReadBufferSize(buffer)
> self.socket.bind(QHostAddress.LocalHost, port,
> QtNetwork.QUdpSocket.ShareAddress)
> self.socket.readyRead.connect(self.dataArrived)
> msg=("Socket opened at host=%s, port=%d." % (host, port))
> # Stop Communication.
> else:
> # Close socket
> self.socket.disconnectFromHost()
> self.socket.waitForDisconnected()
> self.socket.close()
> msg=("Socket closed at host=%s, port=%d." % (host, port))
>
> Sender:
>
> import socket
>
> # Set the socket parameters
> host = "localhost"
> port = 6268
> addr = (host, port)
>
> service = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>
> data = "This is a test string."
> try:
> service.connect(addr)
> service.send(data)
> except Exception, (value, message):
> if service:
> service.close()
> print message
> service.close()It seems Receiver script is not opening the port for
> listening.
Aren't you mixing UDP and TCP concepts here? Sender speaks hindi, while
receiver waits for sanskrit answers ;-)
Pete
More information about the PyQt
mailing list