-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.dart
More file actions
24 lines (22 loc) · 862 Bytes
/
main.dart
File metadata and controls
24 lines (22 loc) · 862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import 'dart:io';
import 'dart:typed_data';
void main(List<String> args) {
RawDatagramSocket.bind(InternetAddress.anyIPv4, 4444).then((RawDatagramSocket socket){
print('Datagram socket ready to receive');
print('${socket.address.address}:${socket.port}');
socket.listen((RawSocketEvent e){
Datagram d = socket.receive();
if (d == null) return;
print(d.data);
ByteBuffer buffer = Int8List.fromList(d.data).buffer;
ByteData byteData = ByteData.view(buffer);
double result = byteData.getFloat64(0, Endian.little);
print('Datagram from ${d.address.address}:${d.port}: ${result}');
result += .1;
byteData.setFloat64(0,result, Endian.little);
buffer = byteData.buffer;
List<int> finalData = buffer.asInt8List().toList();
socket.send(finalData, d.address, d.port);
});
});
}