I am clearing that my task is to send the message from android and receiving the the message to Web Chrome through wifi connectivity the wifi network should be same for both devices
I used UDP but it is not supproting for the chrome so I switched to the WebSocketChannel in which
I set the port to be static by the terminal command flutter run -d chrome –web-port 1234
instead of 1234 I used to change the port number by myself and I used following code, please check this code
`try {
channel = WebSocketChannel.connect(Uri.parse(webSocketUrl));
logger.i("WebSocket connected to $webSocketUrl");
return channel;
} catch (e) {
logger.e("Error connecting to WebSocket: $e");
return null;
}`
`to send message`
`if (channel == null) {
logger.e("WebSocket channel is not initialized.");
return;
} else {
try {
channel.sink.add(message);
log("Sending message: $message");
} catch (e) {
logger.e("Error sending message: $e");
}
}`
`to receive the message`
`if (channel == null) {
logger.e("WebSocket channel is not initialized.");
return;
} else {
channel.stream.listen(
(message) {
runInAction(() {
receivedMessage = message;
log("Received message: $receivedMessage");
logger.i("Received message: $receivedMessage");`your text`
});
},
onError: (error) {
logger.e("Error receiving message: $error");
},
onDone: () {
logger.i("WebSocket connection closed.");
}
);
}`
8271_ANURAG_KANADE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.