This repository has been archived on 2025-06-01. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
compLIB/client_s2/main.py
Konstantin Lampalzer 9b567b8c6c Protobuf prototype
2022-03-18 18:11:16 +01:00

36 lines
957 B
Python

import socket
import sys
import os
import CompLib_pb2
SOCKET_PATH = "/tmp/compLib"
def send(data, size):
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock:
sock.connect(SOCKET_PATH)
sock.sendall(size.to_bytes(1, byteorder='big'))
sock.sendall(data)
responseSizeBytes = sock.recv(1)
responseSize = int.from_bytes(responseSizeBytes, byteorder="big")
print(responseSize)
responseBytes = sock.recv(responseSize)
genericResponse = CompLib_pb2.GenericResponse()
genericResponse.ParseFromString(responseBytes)
print(genericResponse)
# reponseBytes =
def main():
readSensorsRequest = CompLib_pb2.ReadSensorsRequest()
# readSensorsRequest.header = CompLib_pb2.Header()
readSensorsRequest.header.message_type = readSensorsRequest.DESCRIPTOR.full_name
send(readSensorsRequest.SerializeToString(), readSensorsRequest.ByteSize())
main()