0

I have client-server application when communicotion by simple binary protocol. The binary protocol have 12 byte header (see code) when four byte is length of data [datasize] and 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 to receive binary data from client by libuv? Do You know examples of processing binary data protocol by libuv?

user1514692
  • 60
  • 1
  • 8

1 Answers1

2

libuv uses the asyn events to notify new data arrived after you call uv_read_start. So you can get the binary data chunks from client in the callback function, something like void data_callback(uv_stream_t *, size_t, uv_buf_t).

All you need to do next is composing the binary data chunks to the high layer protocol. You can setup a state machine for each client, feed it with data chunks and then emit the package to higher layer when a protocol package has completed.

I have a protocol parsing example similar with yours. It is a tcp client based on libuv. The protocol parsing module is here: package.h and package.c. Hoping it is helpful for you. :)

changchang
  • 549
  • 4
  • 11