May 2019
Intermediate to advanced
542 pages
13h 37m
English
QTcpServer has handled the reception of messages; now we need to implement sending messages. To do this, we first need to create a QTcpSocket object to be our client socket.
Let's add this to the end of __init__():
self.client_socket = qtn.QTcpSocket() self.client_socket.error.connect(self.on_error)
We've created a default QTcpSocket object and connected its error signal to our error handling method. Note that we don't need to bind this socket because it won't be listening.
To use the client socket, we'll create a send_message() method; just as with our UDP chat, this method will start by formatting the message it into the raw transmission string:
def send_message(self, message): raw_message = f'{self.username}{self.delimiter}{message}' ...Read now
Unlock full access