c - libuv - How to use binary protocol -


i have client-server application when communicotion simple binary protocol. binary protocol have 12 byte header (see code) when 4 byte length of data [datasize] , data block size of datasize.

struct header {     int32_t message_type;     int32_t message_id;     int32_t data_size; }; 

dataflow:


header | data | header | data |


how receive binary data client libuv? know examples of processing binary data protocol libuv?

libuv uses asyn events notify new data arrived after call uv_read_start. can binary data chunks client in callback function, void data_callback(uv_stream_t *, size_t, uv_buf_t).

all need next composing binary data chunks high layer protocol. can setup state machine each client, feed data chunks , emit package higher layer when protocol package has completed.

i have protocol parsing example similar yours. tcp client based on libuv. protocol parsing module here: package.h , package.c. hoping helpful you. :)


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -