Skip to content

Commit cde1415

Browse files
authored
Merge pull request #54 from masgari/main
send large data in 2kb chunks
2 parents 7fd3be6 + a713177 commit cde1415

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

adafruit_wiznet5k/adafruit_wiznet5k_wsgiserver.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,17 @@ def finish_response(self, result, client):
124124
response += "\r\n"
125125
client.send(response.encode("utf-8"))
126126
for data in result:
127-
if isinstance(data, bytes):
127+
if not isinstance(data, bytes):
128+
data = data.encode("utf-8")
129+
if len(data) < 0x800:
128130
client.send(data)
129131
else:
130-
client.send(data.encode("utf-8"))
132+
# split to chunks of 2 kb
133+
data_chunks = [
134+
data[i : i + 0x800] for i in range(0, len(data), 0x800)
135+
]
136+
for data_chunk in data_chunks:
137+
client.send(data_chunk)
131138
gc.collect()
132139
finally:
133140
client.disconnect()

0 commit comments

Comments
 (0)