I'm stuck on the dumbest possible hindrance I can think of. I'm developing a flutter app that should send via TCP socket (on a local wifi network) an array of bytes.
Said bytes are raw and not representative of meaningful characters in any encoding (I have values like 0xFF and so on). My code succesfully connects and sends data by using the socket write
method. Unfortunately that method only takes an encoded String
as argument, and creating one from char codes botches up my message.
Here is my code:
var message = Uint8List(4);
var bytedata = ByteData.view(message.buffer);
bytedata.setUint8(0, 0x01);
bytedata.setUint8(1, 0x07);
bytedata.setUint8(2, 0xFF);
bytedata.setUint8(3, 0x88);
socket.write(String.fromCharCodes(message))
while 0x01 and 0x07 are received correctly, 0xFF and 0x88 get turned into a couple of other bytes, 0xC3BF and 0xC287 (checked with netcat -l 8080 | hexdump
command).
I've googled for a while now for a way to send raw bytes without encoding them as strings, but couldn't find anything. Is it simply not contemplated? I realize Flutter and Dart are meant for high level web development, but it seems absurd to me.