fstream/modules/fstream/messages.py

15 lines
494 B
Python

global getResponse
def getResponse(connection,maxLength = 0):
data = b''
data = recv(connection,4)
if not data: return False
nul = recv(connection,1)
if not nul: return False
if nul != b"\x00": return False
requestLength = int.from_bytes(data,"big")
if maxLength != 0 and requestLength > maxLength: return False
return recv(connection,requestLength)
global sendResponse
def sendResponse(connection,data):
connection.sendall(len(data).to_bytes(4,"big") + b"\x00" + data)