50 lines
1.2 KiB
Python
Executable File
50 lines
1.2 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import sys
|
|
sys.path.append("../ServerCore")
|
|
import socket # noqa
|
|
import json # noqa
|
|
from JSONStreamParser import JSONStreamParser # noqa
|
|
import argparse # noqa
|
|
|
|
|
|
def send_request(host, port, datatype, position, data):
|
|
parser = JSONStreamParser()
|
|
|
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
|
s.connect((host, port))
|
|
message_object = {}
|
|
|
|
if datatype is not None:
|
|
message_object['datatype'] = datatype
|
|
|
|
if position is not None:
|
|
message_object['position'] = position
|
|
|
|
if data is not None:
|
|
message_object['data'] = data
|
|
|
|
s.sendall(json.dumps(message_object).encode())
|
|
|
|
while parser.isQueueEmpty():
|
|
parser.appendRawData(s.recv(4096))
|
|
|
|
print("received data:\n", parser.popAsJSON())
|
|
|
|
s.close()
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(
|
|
description="tester for the voxel Server protocoll")
|
|
parser.add_argument('--datatype')
|
|
parser.add_argument('--position', nargs=3, type=int)
|
|
parser.add_argument('--data')
|
|
|
|
args = parser.parse_args()
|
|
send_request('127.0.0.1', 5050, args.datatype, args.position, args.data)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|