socket.io-client-dart
socket.io-client-dart copied to clipboard
Timeout while connecting to hardware device via Wifi
Hi,
I am trying to send data to a hardware device which is connected via Wifi. I have device's ip address and port number and used following code to send. But it always shows 'Connection Error : timeout'.
I am using 'socket_io_client: ^2.0.0-beta.2'
_socket = io(
"ws://192.168.4.1:81/",
OptionBuilder()
.setTransports(['websocket'])
.enableForceNew()
.disableAutoConnect()
.build());
_socket.connect();
_socket.onConnect((data) =>
{AppDebugLog.println("In onConnect : ${data.toString()}")});
_socket.onConnectError((data) => {
AppDebugLog.println(
"In onConnectError : ${data.toString()}")
});
_socket.onConnectTimeout((data) => {
AppDebugLog.println(
"In onConnectTimeout : ${data.toString()}")
});
_socket.onError((data) =>
{AppDebugLog.println("In onError : ${data.toString()}")});
_socket.onDisconnect((data) => {
AppDebugLog.println(
"In onDisconnect : ${data.toString()}")
});
I am sending data using following;
_socket?.send([msg]);
Any help will be appreciated. Thanks in advance.
same issue in my case i have a textfield to set socket server url when this url is wrong the socket dosent connet and goes to socket.on('connect_error', (data){}) and after i put the correct url it connects but soon it shows connection timeout and disconnects