I'm working with winsock TCP sockets. I receive a char array from the recv function. We send the value 0x27 and we receive the following data: array[0]=27 (dec). Why does it so work? How can I have the original hex value??
The problem is that, we can see with wireshark that we've sent the byte 0x27 (in decimal: 39). And the returned character array from the recv-function is a 27 in decimal, that is 0001 1011=27(dec) and we want to have
0010 1101 =27(hex).
why does it so work? and how can I do to get the hex expression?
its just the debugger which is showing you wrong values because the values wont change when you receive().
you must be typecasting the value when you sent it from hex to char.
similarly typecast it back from char to hex and you will certainly see the correct value.
its just a display problem as kbw said. the values are correct, its just that debugger is showing wrong values as it doesnt know what to expect.
you can post some part of code(client and server part) so that the thing could be a little clear.
I use this function to receive the buffer
msgLength = recvfrom(socketIn, buffer, l_buffer,0,(SOCKADDR*)&clientService, &l_client);
In a following if-statement, i got the result, that my buffer at position 0 is not equal to 0x27.
But it is.
The result is true, when i compare the buffer[0] with 27 (in decimal).
I don't know why.
Wireshark gives me the correct value, which is 0x27.
can you tell me the signatures of sent and recv functions.
because i am not able to know what are the datatypes of various parameters?
like recvfrom is receiving similarly there must be a function which sending from the client.
write the declaration of the functions?
see when you code you work in decimal only.
like if you are doing this: int i = 39;
but sometimes the debugger shows the values in hex. so if you are putting 39 the debugger is showing 0x27 which is actually 39.
i think there is some confusion using the debugger only.
because if you are sending 27dec then you must receive 27dec only, it cant change to 27hex.
to send you do this: sendto(socket,(void*)&msg, sizeof(msg), ...rest of the parameters...);
to receive you do this:
1 2 3
DumpReqParameters recv_msg;
recvfrom(socket, (void*)&recv_msg, sizeof(recv_msg), ...rest of the parameters...);
unsignedshort len = recv_msg.tr_src_mLength;
i have to make a structure for all the incoming messages?
isn't it a little bit complicated?
I got the following error: "Can not convert parameter 2 void* to char*", when i write (void*)&recv_msg.
but then you dont have any option to send the whole data..this is the only way to send data across network..
you can find a way to optimize all the bulky stuff.. thats it.