Skip to content

Commit

Permalink
feat: Improve server communication using a buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
Marius-P1 committed Jun 22, 2024

Unverified

This user has not yet uploaded their public signing key.
1 parent de2cd87 commit 634a8fc
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions ai/src/AI.py
Original file line number Diff line number Diff line change
@@ -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):
@@ -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
@@ -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
@@ -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

0 comments on commit 634a8fc

Please sign in to comment.