1
0
Fork 0
mirror of https://github.com/besterprotocol/besterd synced 2023-12-13 21:00:32 +01:00
besterd/testing/tbkHandler.py

27 lines
812 B
Python
Raw Permalink Normal View History

2020-05-02 17:40:40 +02:00
import socket
import json
import os
def runTest():
os.remove("../aSock")
handlerSock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
handlerSock.bind("../aSock")
handlerSock.listen()
while True:
print("Waiting for connection to (this) handler...")
serverSock = handlerSock.accept()[0]
size=int.from_bytes(serverSock.recv(4), "little")
receivedBys = json.loads(serverSock.recv(size).decode())
print(receivedBys)
bys = json.dumps({
"header" : {
"status" : "0",
"command" : {"type" : "sendClients", "data": ["tbk", "skippy"]}
}, "data" : receivedBys })
print(serverSock.send(len(bys).to_bytes(4, "little")))
print(serverSock.send(bys.encode()))
runTest()