Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read byte array data in Dart?

Tags:

flutter

dart

connecting TCP Socket server and sending Request. and also Server sends the response in Byte array. How to read byte array data in dart.

Socket.connect('localhost', 8081)
  .then((socket) {
//Establish the onData, and onDone callbacks
socket.listen((data) {
  print(new String.fromCharCodes(data).trim()); //Here data is byte[]
  //How to read byte array data

},
    onDone: () {
      print("Done");
      // socket.destroy();

    },
    onError: (e) {
      print('Server error: $e');
    });
 socket.add([255, 12, 0, 11, 0, 9, 34, 82, 69, 70, 84, 65, 72, 73, 76]);
 });
}
like image 228
Dileep Avatar asked Oct 23 '25 16:10

Dileep


1 Answers

It depends on with data type was encoded to bytes. Let's suppose it's String Then you can do it with dart:convert library.

import 'dart:convert' show utf8;

final decoded = utf8.decode(data);
like image 188
Ilya Avatar answered Oct 26 '25 07:10

Ilya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!