I am trying to figure out how to send data over UDP/TCP from my flutter application to my server which has .net applications which listen for UDP and TCP . I searched about it and I found that there is a package named web_socket_channel and I tried that it is working with the testing server ws://echo.websocket.org but when I replace the echo.websocket.org with my server IP address or domain name it doesn't work even i am not getting any errors back so I couldn't figure out what's going on. Is there something wrong? or am i doing something wrong? Can someone help me with my demo code :
WebSocketChannel channel;
String text = "";
void sendSocket() {
String message = "message_text"
if(message.isNotEmpty)
channel.sink.add(message);
}
getStreamData() {
channel.stream.asBroadcastStream().listen((event) {
if (event != null)
print(event);
});
}
@override
void dispose() {
channel.sink.close();
super.dispose();
}
@override
void initState() {
try {
channel = IOWebSocketChannel.connect(
'ws://127.0.0.1:8889');
getStreamData();
super.initState();
} catch (e) {
print(e.toString());
}
}
I appreciate your help. Thanks you so much.