i'm try to convert int to byte and cant find an example working fo me
i need convert int in byte or bytes to sent in tcp ip
final server = await ServerSocket.bind(ip,port);
try{
server.listen((Socket socket) {
int a = 10; // line feed
int b = 36; // $
int c = 122; // z
const sec = Duration(seconds:1);
Timer.periodic(sec,(Timer t) {
socket.wite('data : $a,$b,$c');
});
} on SocketExeption catch(ex) {
print(ex.message);
}
and i recive
|d|a|t|a| |:|1|0|,|3|6|,|1|2|2|
how i can recive
|d|a|t|a| |:|LF|,|$|,|z| or |d|a|t|a| |:|0x0A|,|$|,|z|
i work with plc and he like bytes in absolute indexing
it's possible?
if use
int a = 0;
for(;;){
socket.write(String.fromCharCode(a));
a++;
if(a>=256)a=0;
}
recive over tcp ip
byte0 =00.01....4F........7D.7E.7F.C2.C2....C2.C2..C2.C2.C3.C3.C3..C3.C3.00.01...
byte1 =00.00....00........00.00.00.80.81....84.85..BE.BF.80.81.82..BE.BF.00.00...
In any case i can use strings but for some protocols it's a huge of data, minimun moltiply x4 if use 3 char and one separator
i try use RTC with flutter on windows app
for the last project i create a
javaServer<-low side code bit/byte->plc
and
flutter<-json->javaServer
i think is ugly
work thanks LEPSCH
try {
client.listen((Socket socket) {
debugPrint('New TCP client ${socket.address.address}:${socket.port} connected.');
List<int> bytes = List.empty(growable: true);
for (var i = 0; i < 255; i++) {
bytes.add(i);
}
Timer.periodic(const Duration(seconds: 1), (Timer t) {
for (var i = 0; i < 255; i++) {
socket.add([bytes[i]]);
}
});
});
} on SocketException catch (ex) {
debugPrint(ex.message);
Timer.periodic(Duration(seconds: 1), (Timer t) {
startServer();
});
}