Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 22f2da3

Browse files
committed
merge
2 parents f873790 + debcb9d commit 22f2da3

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

Doc/howto/sockets.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,15 @@ length message::
204204
totalsent = totalsent + sent
205205

206206
def myreceive(self):
207-
msg = b''
208-
while len(msg) < MSGLEN:
209-
chunk = self.sock.recv(MSGLEN-len(msg))
207+
chunks = []
208+
bytes_recd = 0
209+
while bytes_recd < MSGLEN:
210+
chunk = self.sock.recv(min(MSGLEN - bytes_recd, 2048))
210211
if chunk == b'':
211212
raise RuntimeError("socket connection broken")
212-
msg = msg + chunk
213-
return msg
213+
chucks.append(chunk)
214+
bytes_recd = bytes_recd + len(chunk)
215+
return b''.join(chunks)
214216

215217
The sending code here is usable for almost any messaging scheme - in Python you
216218
send strings, and you can use ``len()`` to determine its length (even if it has

0 commit comments

Comments
 (0)