Fix networker send bugs.

This commit is contained in:
Captain ALM 2022-12-10 20:59:46 +00:00
parent a99a207c34
commit 095dc97d4e
Signed by: alfred
GPG Key ID: 4E4ADD02609997B1
1 changed files with 8 additions and 2 deletions

View File

@ -47,7 +47,7 @@ class Message:
toReturn = {"mtype":self.mtype, "header":self.header, "ident__":"Message"}
if type(self.content) == bytes or type(self.content) == bytearray:
toReturn["contentb64"] = True
toReturn["content"] = base64.b64encode(bytes(self.content)).decode('utf-8')
toReturn["content"] = base64.b64encode(bytes(self.content)).decode()
else:
toReturn["contentb64"] = False
toReturn["content"] = self.content
@ -164,7 +164,12 @@ class Connection:
def send(self, addr, m):
if self.active and self.actives[addr]:
try:
toSend = bytes(self.translator.toString(m))
toSendData = self.translator.toString(m)
toSend = []
if type(toSendData) == bytes or type(toSendData) == bytearray:
toSend = bytes(self.translator.toString(m))
else:
toSend = bytes(self.translator.toString(m), encoding='utf-8')
sendLength = len(toSend)
if sendLength < 1:
print("Message for: " + addr + " empty?")
@ -189,6 +194,7 @@ class Connection:
self.actives[addr] = False
except:
print("A send failure has occured for: " + addr)
#print(traceback.format_exc())
def close(self):
self.active = False