Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl Websocket Server causing "could not decode a text frame as UTF-8" in Chrome

Tags:

websocket

perl

When using Perl's Websocket server, if I send a json message using send_utf8 that's longer than about 16,000 characters, it causes the connection to the websocket to be killed in Chrome with the message:

"Could not decode a text frame as UTF-8".

Is there some restriction on the length of messages that can be sent by this Websocket server, and is there a way of getting around this restriction?

like image 831
Vijay Boyapati Avatar asked Sep 29 '22 04:09

Vijay Boyapati


2 Answers

It fails because (as of 0.001003) Net::WebSocket::Server::Connection initializes its Protocol::WebSocket::Frame objects without setting "max_payload_size" which overrides the 65535 byte limit. The problem can be easily resolved if the module author updates those calls to allow larger buffers, or better, to pass through a user defined value.

like image 143
Ben Grimm Avatar answered Dec 31 '22 20:12

Ben Grimm


Apparently, it's possible to set the payload size in the Protocol::WebSocket::Frame constructor (https://github.com/vti/protocol-websocket/issues/24#issuecomment-27095561).

Unfortunately the docs on cpan seem to be missing that information.

Try this:

$hs->build_frame(buffer => $my_data, max_payload_size => 200000)->to_bytes);
like image 23
RandomAndy Avatar answered Dec 31 '22 21:12

RandomAndy