I need to send data from C++
to C#
.
On C++
side, under Linux, I am using ZMQ
library version 4.1.4
.
C#
side is using clrzmq4
library based on 4.1.5 version
.
So the part where I send message in C++
:
char tempStr[] = "ABCD";
zmq_msg_t zmsg;
zmq_msg_init_size(&zmsg, 4);
memcpy(zmq_msg_data(&zmsg), tempStr, 4);
int rc = zmq_send(reqSocket, &zmsg, sizeof(zmsg), 0);
zmq_msg_close(&zmsg);
C#
code to retrieve message:
ZFrame request = responder.ReceiveFrame();
byte[] reqBytes = new byte[100];
int n = request.Read(reqBytes, 0, 100);
The problem is that byte array is including all 64 bytes of zmq_msg_t
. The actual data is starting from offset 16.
Question
- how to properly extract data in this case? Extracting by hard coding the offset in my code is simply ugly, because one day zmq_msg_t
may be changed from sender side and data will be located somewhere else. Other option is to avoid using zmq_msg_t
, when both sides are not using same platform/framework. In the clrzmq4
framework I can see there are delegates for zmq_msg_t
types, but not sure how to use them and whether they intended for public usage.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…