0

I'm trying to receive huge amount of data from libwebsocket.

case LWS_CALLBACK_RECEIVE: {
    lws_write(wsi, in, len, LWS_WRITE_TEXT);
    break;
}

But this code just send small portions of the data by couple messages. So they are chunked by default and chunk size is limited by 4096.

I need some way how to receive each packet then concat and send back to client.

xercool
  • 883
  • 1
  • 8
  • 24
  • What have you tried ? – marcolz Oct 07 '19 at 07:49
  • I tried strcat but I can't calculate whole message size in advance. So there is method `lws_is_final_fragment`. I tried just concat string... but still it worked wrong... basically idk what to do.. – xercool Oct 07 '19 at 07:51
  • @featureoffuture The `strcat` function is for strings. You need to use `memcpy`. Allocate a large buffer. Copy fragments into it until you've copied the last fragment. Then process the buffer. – David Schwartz Oct 07 '19 at 08:47
  • @DavidSchwartz sounds reasonable. I tried that too and that didn't work for me (probably I did it wrong). But can you make just short algorithm snippet for me?... Idk actually how to "append" data. – xercool Oct 07 '19 at 09:32
  • Just copy the new data to appear right after the old data. Show your code. – David Schwartz Oct 07 '19 at 09:34

0 Answers0