eric7/Cooperation/Connection.py

branch
eric7
changeset 8318
962bce857696
parent 8312
800c432b34c8
child 8356
68ec9c3d4de5
equal deleted inserted replaced
8316:0c7a44af84bc 8318:962bce857696
5 5
6 """ 6 """
7 Module implementing a class representing a peer connection. 7 Module implementing a class representing a peer connection.
8 """ 8 """
9 9
10 from PyQt5.QtCore import pyqtSignal, QTimer, QTime, QByteArray 10 from PyQt6.QtCore import pyqtSignal, QTimer, QTime, QByteArray
11 from PyQt5.QtNetwork import QTcpSocket, QHostInfo 11 from PyQt6.QtNetwork import QTcpSocket, QHostInfo
12 12
13 from E5Gui import E5MessageBox 13 from E5Gui import E5MessageBox
14 from E5Gui.E5Application import e5App 14 from E5Gui.E5Application import e5App
15 15
16 import Preferences 16 import Preferences
233 233
234 if not self.__isGreetingMessageSent: 234 if not self.__isGreetingMessageSent:
235 self.__sendGreetingMessage() 235 self.__sendGreetingMessage()
236 236
237 self.__pingTimer.start() 237 self.__pingTimer.start()
238 self.__pongTime.start() 238 self.__pongTime = QTime.currentTime()
239 self.__state = Connection.ReadyForUse 239 self.__state = Connection.ReadyForUse
240 self.readyForUse.emit() 240 self.readyForUse.emit()
241 241
242 while self.bytesAvailable(): 242 while self.bytesAvailable():
243 if ( 243 if (
253 253
254 def __sendPing(self): 254 def __sendPing(self):
255 """ 255 """
256 Private slot to send a ping message. 256 Private slot to send a ping message.
257 """ 257 """
258 if self.__pongTime.elapsed() > PongTimeout: 258 if self.__pongTime.msecsTo(QTime.currentTime()) > PongTimeout:
259 self.abort() 259 self.abort()
260 return 260 return
261 261
262 self.write(QByteArray("{0}{1}1{1}p".format( 262 self.write(QByteArray("{0}{1}1{1}p".format(
263 Connection.ProtocolPing, SeparatorToken).encode("utf-8"))) 263 Connection.ProtocolPing, SeparatorToken).encode("utf-8")))
387 self.__username, str(self.__buffer, encoding="utf-8")) 387 self.__username, str(self.__buffer, encoding="utf-8"))
388 elif self.__currentDataType == Connection.Ping: 388 elif self.__currentDataType == Connection.Ping:
389 self.write(QByteArray("{0}{1}1{1}p".format( 389 self.write(QByteArray("{0}{1}1{1}p".format(
390 Connection.ProtocolPong, SeparatorToken).encode("utf-8"))) 390 Connection.ProtocolPong, SeparatorToken).encode("utf-8")))
391 elif self.__currentDataType == Connection.Pong: 391 elif self.__currentDataType == Connection.Pong:
392 self.__pongTime.restart() 392 self.__pongTime = QTime.currentTime()
393 elif self.__currentDataType == Connection.GetParticipants: 393 elif self.__currentDataType == Connection.GetParticipants:
394 self.getParticipants.emit() 394 self.getParticipants.emit()
395 elif self.__currentDataType == Connection.Participants: 395 elif self.__currentDataType == Connection.Participants:
396 msg = str(self.__buffer, encoding="utf-8") 396 msg = str(self.__buffer, encoding="utf-8")
397 if msg == "<empty>": 397 if msg == "<empty>":

eric ide

mercurial