-
Notifications
You must be signed in to change notification settings - Fork 0
/
rec.dart
33 lines (27 loc) · 848 Bytes
/
rec.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import 'dart:io';
import 'dart:convert';
import 'dart:async';
void main() async {
const String op = '9';
await sendCommand(op);}
Future<void> sendCommand(String command) async {
var host = InternetAddress('192.168.29.23');
var port = 80;
// Connect to the server
Socket clientSocket = await Socket.connect(host, port);
clientSocket.write(utf8.encode(command));
await clientSocket.flush();
/*
await clientSocket.listen(
(event) {
String message = String.fromCharCodes(event);
print(message);});
*/
final stream = clientSocket.transform(StreamTransformer.fromHandlers(handleData: (data, sink)
{sink.add(utf8.decode(data));},)); // Transform the incoming bytes to a string and split by lines
await for (final line in stream) {
print(line);
}
await clientSocket.close();
print('destroyed');
}