2-Protocol-Design Sistemas Distribuidos
2-Protocol-Design Sistemas Distribuidos
Protocol design
1
Contents
●
What is a protocol?
●
Syntax
●
Semantics
●
Synchronization
●
TFTP example
●
Example: Sockets
●
Example: Protocol Buffers
And to read a
512-byte file?
https://datatracker.ietf.org/doc/html/rfc1350
Source: dzone
JSON request was 789 bytes versus the
Protobuf at 518 bytes.
Distributed Systems :: Protocol Design 22
Protocol Buffers
●
Manage marshaling from the programming
language structures to binary sequences and
vice-versa.
●
Builtin types:
●
bool, string, int32, int64, float, double, etc.
●
Enumerations, nested, etc.
Python
marshaling
Source: massivetechinterview.blogspot.com.es
https://protobuf.dev/programming-guides/proto3/
● udp-client.py
socket.struct$ ./udp-server.py
New message ('127.0.0.1', 36137)
Sensor 8 (2) value:16.30 bar
Run client:
socket.struct$ ./udp-client.py localhost
b'\x00\x08\x02A\x82ff\x03bar'
Compile:
See and play with:
● sensor.proto
socket.protobuf$ make
protoc -I . --python_out=. sensor.proto ● udp-server.py
● udp-client.py
Run server:
socket.protobuf$ ./udp-server.py
sensor: ('127.0.0.1', 53957),
raw-data: b'\x08\x01\x10\x01\x1d\xcd\xccL>"\x05kg/m3'
Sensor 1 (HUMIDITY) value:0.20 kg/m3
Run client:
socket.protobuf$ ./udp-client.py localhost
29