I have a C++ client/server set up and I need to transfer a pointer (specifically, uint8_t*
) between them.
EDIT: the buffer that the pointer points to
Using the traditional send/recv
does not appear to work (requires a char*
), and ideally I would send this pointer as part of a packet with some other variables.
What is the best way of doing this?
Server side to illustrate:
char recvbuf[DEFAULT_BUFLEN];
int recvbuflen = DEFAULT_BUFLEN;
int iResult = recv( this->ClientSocket, recvbuf, recvbuflen, 0 );
if( iResult > 0 )
{
// ideally recvbuf would contain the pointer
// Do some stuff
// Send the buffer back to the sender
std::string result = "Message received";
// ideally here I would be sending my pointer, not this string
int iSendResult = send( this->ClientSocket, result.c_str(), (int)strlen( result.c_str() ), 0 );
if( iSendResult == SOCKET_ERROR )
{
printf( "send failed with error: %d\n", WSAGetLastError() );
closesocket( this->ClientSocket );
WSACleanup();
return false;
}