Networking Reference
In-Depth Information
You could send a message such as world as in our example with the null byte,
as follows:
zmq_msg_init_data_(&request, "world", 6, NULL, NULL);
However, you would send the same message in Erlang as follows:
erlzmq:send(Request, <<"world">>)
Let's say our C client connects to a ZeroMQ service written in Erlang and we send the
message world to this service. In this case Erlang will see it as world . If we send the
message with the null byte, Erlang will see it as [119,111,114,108,100,0] . Instead
of a string, we would get a list that contains some numbers! Well, those numbers are
the ASCII-encoded characters. However, it is not interpreted as a string anymore.
You cannot rely on the fact that a message coming from a ZeroMQ service is safely
terminated when you work in C.
Strings in ZeroMQ are fixed in length and are sent without the null byte.
So, ZeroMQ strings are transmitted as some bytes (the string itself in this
example) along with the length.
W
O
R
L
D
Length: 5
A ZeroMQ string
Checking the ZeroMQ version
It is quite useful to know which ZeroMQ version you are using. Knowing the
exact version is helpful in some scenarios to avoid unwanted surprises. For example,
there are some differences between ZeroMQ 2. x and ZeroMQ 3. x , such as deprecated
methods; therefore, if you know the exact ZeroMQ version you have on your
machine, you would avoid using deprecated methods.
#include <stdio.h>
#include "zmq.h"
int main (int argc, char const *argv[]) {
 
Search MirCeyron ::




Custom Search