M
msosno01
I have Java client that connects to C++ server. The client sends
integer in binary using DataOutputStream write function. I am reading
these data into buffer. I have to convert this buffer back into
integer, but I am not sure how to do it.
This is my code:
int32_t var1;
uint8_t buf[4];
soc = accept();
while (true)
{
socket->recv(&buf, 4);
var1 = htonl(buf);//here I have to do casting. My supervisor
said that I must
//use "void *".
//I tried different combinations
like: (char*)(void *)buf, but everything failed
//in the best case, I've been
getting some huge numbers (all I was sending
//was numerical one)
}
Any help is appreciated.
integer in binary using DataOutputStream write function. I am reading
these data into buffer. I have to convert this buffer back into
integer, but I am not sure how to do it.
This is my code:
int32_t var1;
uint8_t buf[4];
soc = accept();
while (true)
{
socket->recv(&buf, 4);
var1 = htonl(buf);//here I have to do casting. My supervisor
said that I must
//use "void *".
//I tried different combinations
like: (char*)(void *)buf, but everything failed
//in the best case, I've been
getting some huge numbers (all I was sending
//was numerical one)
}
Any help is appreciated.