Here are the two version of my Receiver & Sender scripts:
Receiver
# Start Communication.
if status:
# Create socket
self.socket.setReadBufferSize(buffer)
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))
# Start Communication.
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))
To copy to clipboard, switch view to plain text mode
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()
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()
To copy to clipboard, switch view to plain text mode
The problem is in Receiver script
Bookmarks