I have worked when both the ends of communication were based on erlang and documentation makes it clear that using {packet, N} appends a header with the size of the message and gen_tcp:recv/2 removes the header when receiving. This is pretty straightforward. However, if the receiving program is not erlang based, rather c++ based, how to I only parse the header and know the size of the message so that I can allocate that amount of memory. I used till now,
//Receive a message from client
while( (read_size = recv(sock , client_message , 2000 , 0)) > 0 )
{
//end of string marker
client_message[read_size] = '\0';
write(sock , client_message , strlen(client_message));
//clear the message buffer
memset(client_message, 0, 2000);
}
But not sure how to get that header and then use the ei_module to get the real decoded value.
This is how I have been decoding the message.
code here This was when the client connected with the option {packet,0} so there was no header with size. To allow dynamic memory allocation, I am starting to use {packet, N} but unsure how to read that header? Thank you in advance.