I am trying to send a String via a socket using a perl program. I am getting an error saying that the text contains a wide character, and the socket can't deal with that. Is there a way to either:
A: Turn on wide characters through the socket
or
B: Remove all wide characters from a string?
It means you're trying to send text over a handle, yet handles can only communicate bytes. You need to serialise the text into bytes. Specifically, you want to encode the text. You can use Encode's encode
function
print $sock encode('some_encoding', $text);
or you can instruct the socket to do it for you
binmode $sock, ':encoding(some_encoding)'; # once
print $sock $text;
Replace some_encoding
with the encoding expected by the other end of the socket (e.g. UTF-8
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With