I'm not sure I understand you correctly as I always wait for "nextBlockSize". Here is the simplified server code and below I show the results of my tests. It seems a weird exception is raised.


Qt Code:
  1. ...
  2. while self.socket.state() == QAbstractSocket.ConnectedState:
  3.  
  4. self.nextBlockSize = 0
  5.  
  6. while self.socket.bytesAvailable() < SIZEOF_UINT16:
  7. self.socket.waitForReadyRead(-1)
  8.  
  9. print("Bytes available: %d" % self.socket.bytesAvailable())
  10. self.nextBlockSize = stream.readUInt16()
  11.  
  12. if self.nextBlockSize == 0:
  13. print("GameServer: Problem with QTcpSocket?!\n"
  14. "QDataStream status(): %d" % stream.status())
  15. return
  16.  
  17. while self.socket.bytesAvailable() < self.nextBlockSize:
  18. self.socket.waitForReadyRead(-1)
  19.  
  20. print("BlockSize: %d" % self.nextBlockSize)
  21. ...
To copy to clipboard, switch view to plain text mode 

I also print at the client side what it sends (it is represented below by the byte arrays and the lines "SIZE: x" -- in red color).
The printed lines on the console are:

...
b'\x00\x14\x00\x00\x00@\x00\x00\x96\x9d\x05w\xd2\x 90\x00\x00\x03\x84\x00\x00\x01\x9f'
b'\x00\x14\x00\x00\x00@\x00\x00\x96\x9d\x05w\xd2\x 90\x00\x00\x03(\x00\x00\x01\xc7'
SIZE: 22
SIZE: 22

Bytes available: 44
BlockSize: 20
Bytes available: 22
BlockSize: 20
b'\x00\x14\x00\x00\x00@\x00\x00\x96\x9d\x05w\xd2\x 90\x00\x00\x02\xd6\x00\x00\x01\xea'
b'\x00\x14\x00\x00\x00@\x00\x00\x96\x9d\x05w\xd2\x 90\x00\x00\x02\x88\x00\x00\x02\x03'
SIZE: 22

Bytes available: 44
BlockSize: 20
Bytes available: 22
BlockSize: 20
b'\x00\x14\x00\x00\x00@\x00\x00\x96\x9d\x05w\xd2\x 90\x00\x00\x02=\x00\x00\x02\x1c'
Bytes available: 22
BlockSize: 20
SIZE: 22
b'\x00\x14\x00\x00\x00@\x00\x00\x96\x9d\x05w\xd2\x 90\x00\x00\x01\xe1\x00\x00\x02"'
Bytes available: 22
BlockSize: 20
SIZE: 22
b'\x00\x14\x00\x00\x00@\x00\x00\x96\x9d\x05w\xd2\x 90\x00\x00\x01\xc1\x00\x00\x01\xcd'

Bytes available: 22
GameServer: Problem with QTcpSocket?!
QDataStream status(): 1

(Note that the "SIZE:" lines are printed by the client GUI-thread whereas the byte arrays are printed by an independent client thread)

So at the end it seems that I have read past the end of the stream (status == 1), but my code seems correct.
However I just have caught this exception :

------------
Error in sys.excepthook:
TypeError: 'NoneType' object is not callable

Original exception was:
Traceback (most recent call last):
File "/home/tuxico/Projets/PyMagic-git/pm_gameserver.py", line 92, in run
TypeError: unorderable types: int() < NoneType()
------------

and the faulting line is in the code above:

Qt Code:
  1. while self.socket.bytesAvailable() < SIZEOF_UINT16:
To copy to clipboard, switch view to plain text mode 

What does it means?

Thanks for all your patience.