Flutter Websockets Linux
I'm building a desktop flutter application on Linux and I'm having some problems with websockets on localhost. I'm only planning to use the websockets as a way to communicate my py
Solution 1:
I had a similar problem,
try:
conn.sendall(bytes("Your Mes here","utf-8"))
But i am not using the Websocket lib from Flutter, i used dart.io That was my code:
voidgetDataFromServer({String ip, String port}) async{
await Socket.connect(ip, int.parse(port)).then((socket) async {
print('Connected to: ''${socket.remoteAddress.address}:${socket.remotePort}');
socket.cast<List<int>>().transform(json.fuse(utf8).decoder).listen((event) {
setState(() {
data = event;
if (data.isEmpty) data.add(0);
});
});
socket.write("open");
}).onError((error, stackTrace){
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text("Etwas stimmt nicht!"),
));
});
}
Post a Comment for "Flutter Websockets Linux"