besterd/testing/unixSock.py

37 lines
1.1 KiB
Python
Raw Normal View History

2020-04-18 16:43:42 +02:00
import socket
import json
2020-04-18 16:43:42 +02:00
def runTest():
d=socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
d.bind("../aSock")
d.listen()
2020-04-18 19:30:43 +02:00
while True:
print("Waiting for connection to (this) handler...")
2020-04-18 19:30:43 +02:00
s = d.accept()[0]
2020-04-28 23:17:45 +02:00
size=int.from_bytes(s.recv(4), "little")
receivedBys = json.loads(s.recv(size).decode())
print(receivedBys)
2020-04-29 15:40:55 +02:00
2020-04-19 16:51:04 +02:00
bys = json.dumps({
"header" : {
2020-04-19 18:53:16 +02:00
"status" : "0",
2020-04-28 23:17:45 +02:00
"command" : {"type" : "sendClients", "data": ["tbk", "skippy"]}
2020-04-30 15:55:40 +02:00
}, "data" : receivedBys })
2020-04-30 10:33:24 +02:00
print(s.send(len(bys).to_bytes(4, "little")))
print(s.send(bys.encode()))
2020-04-29 15:40:55 +02:00
2020-04-30 15:55:40 +02:00
# bys = json.dumps({
# "header" : {
# "status" : "0",
# "command" : {"type" : "sendServers", "data": ["10.0.0.4:2223"]}
# }, "data" : receivedBys["bruhMsg"] })
2020-04-30 10:33:24 +02:00
#print(s.send(len(bys).to_bytes(4, "little")))
#print(s.send(bys.encode()))
2020-04-29 15:40:55 +02:00
print("Connection to (this) handler finished")
2020-04-18 16:43:42 +02:00
while True: pass
runTest()