You are using invalid cast in send()
function.
int num = 152;
cout << "Trying to send..." << endl;
const char* buff = (const char*)(num);
In above code, you have to use &
for num
, like below code,
const char* buff = (const char*)(&num);
And, also for 'endianness', using htonl()
is much better.
So, I think this code will be better
cout << "Trying to send..." << endl;
int num = 152;
int net_num = htonl(num);
send(sock, (const char*)&net_num, sizeof(int), 0);