I have a small websocket server built with libwebsockets , and I need to receive a string , the problem is that the data received is a *void, but I have trouble to cast it to string .
static int my_protocol_callback(struct libwebsocket_context *context,
struct libwebsocket *wsi,
enum libwebsocket_callback_reasons reason,
void *user, void *in, size_t len)
{
int n, m;
unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 512 +
LWS_SEND_BUFFER_POST_PADDING];
unsigned char *p = &buf[LWS_SEND_BUFFER_PRE_PADDING];
switch (reason) {
case LWS_CALLBACK_ESTABLISHED:
printf("New Connection\n");
break;
case LWS_CALLBACK_SERVER_WRITEABLE:
break;
case LWS_CALLBACK_RECEIVE:
webcmd = static_cast<std::string*>(in);
break;
case LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION:
break;
default:
break;
}
return 0;
}
under the LWS CALLBACK RECEIVE
case, the data is *in
, and I casted it by static_cast<std::string*>(in);
, stored in the webcmd string.
the problem is that the result is a char pointer, instead I need a true char because next I need to split the string.
what do you think about it?
EDIT : resolved the problem .
Under case LWS_CALLBACK_RECEIVE:
tmpcmd = reinterpret_cast <char*>(in);
strcpy(webcmd , tmpcmd );
webcmd is a char array and tmpcmd is a char pointer
thank you for all :D