An Open Source package that allows video game creators, AI researchers and hobbyists the opportunity to learn complex behaviors for their Non Player Characters or agents
As I'm not familiar with low level protocols, Python's handling of them, or the entire gdrl network code, please review this possible solution before potential merging for any issues or errors in understanding.
Here are some assumptions made based on looking at docs and the code:
1) Godot first sends the size of the string in 4 bytes
2) After we receive the size, we try to receive the entire data / string from Godot.
3) In case of recv taking too long or the entire string never being received, timeout will occur after specified interval.
Not data or receiving zero bytes of data usually means that the connection has been terminated by the remote.
Godot tries to send the entire string and on Windows in many cases I am receiving the string with one recv call, however, sometimes, the data might not be received entirely in one call, as recv doesn't guarantee that the entire size specified will be received. The loops should take care of receiving the exact length of data (if possible to do so).
Other changes:
I've replaced the recursion with a while loop, in case the size also doesn't get received completely within the first recv, and the string concatenation with a bytearray, although there may be more optimal solutions for performance. The small time delay is also removed, but please let me know if should be returned.
Performance:
After a short test (not a proper benchmark so it's not conclusive data), this did not improve a single string receive operation's time delay to some noticeable threshold with a single observation with a relatively large array and when setting the recv size to a small value so that it has to repeat multiple times.
Another change to consider is perhaps renaming the method to _get_string if the only purpose is to receive a string from Godot.
As I'm not familiar with low level protocols, Python's handling of them, or the entire gdrl network code, please review this possible solution before potential merging for any issues or errors in understanding.
Here are some assumptions made based on looking at docs and the code: 1) Godot first sends the size of the string in 4 bytes 2) After we receive the size, we try to receive the entire data / string from Godot. 3) In case of recv taking too long or the entire string never being received, timeout will occur after specified interval.
Not data
or receiving zero bytes of data usually means that the connection has been terminated by the remote.recv
call, however, sometimes, the data might not be received entirely in one call, asrecv
doesn't guarantee that the entire size specified will be received. The loops should take care of receiving the exact length of data (if possible to do so).Other changes: I've replaced the recursion with a while loop, in case the size also doesn't get received completely within the first
recv
, and the string concatenation with a bytearray, although there may be more optimal solutions for performance. The small time delay is also removed, but please let me know if should be returned.Performance: After a short test (not a proper benchmark so it's not conclusive data), this did not improve a single string receive operation's time delay to some noticeable threshold with a single observation with a relatively large array and when setting the recv size to a small value so that it has to repeat multiple times.
Another change to consider is perhaps renaming the method to
_get_string
if the only purpose is to receive a string from Godot.