Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents f873790 + debcb9d commit 22f2da3Copy full SHA for 22f2da3
1 file changed
Doc/howto/sockets.rst
@@ -204,13 +204,15 @@ length message::
204
totalsent = totalsent + sent
205
206
def myreceive(self):
207
- msg = b''
208
- while len(msg) < MSGLEN:
209
- chunk = self.sock.recv(MSGLEN-len(msg))
+ chunks = []
+ bytes_recd = 0
+ while bytes_recd < MSGLEN:
210
+ chunk = self.sock.recv(min(MSGLEN - bytes_recd, 2048))
211
if chunk == b'':
212
raise RuntimeError("socket connection broken")
- msg = msg + chunk
213
- return msg
+ chucks.append(chunk)
214
+ bytes_recd = bytes_recd + len(chunk)
215
+ return b''.join(chunks)
216
217
The sending code here is usable for almost any messaging scheme - in Python you
218
send strings, and you can use ``len()`` to determine its length (even if it has
0 commit comments