i'm trying to recieve some binary data on a socket and then decode it,
to decode my data i'm using a dll library, my problem is that the function i need in my library to decode my message takes as input and output arguments BYTE messageDecode( BYTE inmessage, BYTE outmessage),
But to read my data through the socket i have to use a char * because i'm using; nBytes = recv(soc, tempBuffer + offset, 1000, 0); where tempBuffer is char *.
Here is a sample of the code i'm trying to use but still when i print the recieved buffer i get something but when i print it after passing to constr unsigned char* i get nothing:
Expand|Select|Wrap|Line Numbers
- bool Sockets::ReadData( SOCKET soc , char *tempBuffer )
- {
- bool ret = true;
- int offset = 0;
- int nBytes = 0;
- unsigned char *const outBuffer="";
- while( 1 )
- {
- nBytes = recv(soc, tempBuffer + offset, 1000, 0);
- nret = WSAGetLastError();
- if( nret == WSAECONNRESET )
- {
- ret = false;
- break;
- }
- else if (nBytes == 0)
- {
- ret = false;
- break;
- }
- else if (nBytes == -1)
- {
- break;
- }
- else
- {
- offset += nBytes;
- }
- }
- if( offset > 0 )
- {
- unsigned char *const utempBuffer = (unsigned char *const)tempBuffer;// i guess this cast is wrong
- DecodeMessage_byte(utempBuffer, offset,outBuffer);/* Here is my function from the library*/
- return ret;
- }