Skip to content

Commit

Permalink
Merge pull request #249 from FppEpitech/feat/create-a-buffer-for-data…
Browse files Browse the repository at this point in the history
…-received-from-the-server-zappy-ai

Create a buffer for data received from the server - Zappy AI
  • Loading branch information
Marius-P1 authored Jun 22, 2024
2 parents ab651cb + 634a8fc commit ff1d697
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
22 changes: 19 additions & 3 deletions ai/src/AI.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def __init__(self, host, port, teamName):
self.creationTime = time.time_ns()
self.myuuid = str(uuid.uuid4())
self.isRunning = True
self.buffer = ""


def serverCommunicationInThread(self):
Expand All @@ -75,7 +76,12 @@ def serverCommunicationInThread(self):
self.player.currentCallback = self.player.callbacks[0]
self.api.sendData(self.player.currentCommand)
while self.player.currentAction != Action.NONE:
responses = self.api.receiveData().split("\n")
responses = self.buffer + self.api.receiveData()
responses = responses.split("\n")
self.buffer = ""
if responses[-1] != "":
self.buffer = responses[-1]
responses.pop()
for response in responses:
if response == '':
continue
Expand All @@ -86,8 +92,13 @@ def serverCommunicationInThread(self):
print("Regrouping Start", flush=True, file=sys.stderr)
while self.isRunning:
responses = self.api.receiveData(0.1)
if responses is not None :
if responses is not None:
responses = self.buffer + responses
responses = responses.split("\n")
self.buffer = ""
if responses[-1] != "":
self.buffer = responses[-1]
responses.pop()
for response in responses:
if response == '':
continue
Expand All @@ -98,7 +109,12 @@ def serverCommunicationInThread(self):
self.player.currentCallback = self.player.callbacks[0]
self.api.sendData(self.player.currentCommand)
while self.player.currentAction != Action.NONE:
responses = self.api.receiveData().split("\n")
responses = self.buffer + self.api.receiveData()
responses = responses.split("\n")
self.buffer = ""
if responses[-1] != "":
self.buffer = responses[-1]
responses.pop()
for response in responses:
if response == '':
continue
Expand Down
2 changes: 1 addition & 1 deletion ai/src/Network/API.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from ai.src.Utils.Utils import stringifyData
from ai.src.Network.APIException import APIException

LIMIT_TRANSFER = 20480
LIMIT_TRANSFER = 10240

class API:
"""
Expand Down

0 comments on commit ff1d697

Please sign in to comment.