tensor-programming / flutter_websockets

9 stars 8 forks source link

cannot connect to local network channel ws://192.168.1.22:1024' #1

Open NTMS2017 opened 6 years ago

NTMS2017 commented 6 years ago

Hi,

I try to connect to my local network socket services via my local wifi and I am failed. I have server that has a socket services for all system. I can access my local network socket services from internet. The configuration its okay. I can telnet and do the job. Now I want to implement such an action to my personal Flutter Mobile app. I am getting this error. I only change your code to ws://192.168.1.92:1024. If I use flutter_websocket examples it connects and I don't get a error. But once I send data to server I get no response.

Hi,

I create a Flutter App. I made a demo aqueduct restful web api. Now I need help as follows:

1) How to connect my Flutter Mobile App to my aqueduct restful api? 2) How to connect from my aqueduct restful api to internal socket api?

For second question: Manually I can use telnet and connect socket api and send and receive data with using socket internal format. I need to connect to socket from my aqueduct. Meaning is that my aqueduct backend will connect to socket and front will use restful api.

My manual telnet Example:

Last login: Tue Jun 26 15:01:44 on ttys000
Niyazis-MBP:~ niyazitoros$ telnet
telnet> telnet 192.168.1.22 1024
Trying 192.168.1.22...
Connected to 192.168.1.22.
Escape character is '^]'.
Q101:_:49785:_:*************
1:_:2:_:119351:_:NİYAZİ TOROS

Any help please.

@override void initState() { super.initState(); channel = IOWebSocketChannel.connect('ws://192.168.1.92:1024'); controller = TextEditingController(); channel.stream.listen((data) => setState(() => list.add(data))); }

Launching lib/main.dart on Android SDK built for x86 in debug mode... Initializing gradle... Resolving dependencies... Running 'gradlew assembleDebug'... Built build/app/outputs/apk/debug/app-debug.apk. Installing build/app/outputs/apk/app.apk... I/FlutterActivityDelegate(12905): onResume setting current activity to this E/eglCodecCommon(12905): glUtilsParamSize: unknow param 0x00008824 Syncing files to device Android SDK built for x86... D/EGL_emulation(12905): eglMakeCurrent: 0xa75042a0: ver 3 0 (tinfo 0xa7503320) D/ (12905): HostConnection::get() New Host Connection established 0xa7523900, tid 12944 D/EGL_emulation(12905): eglMakeCurrent: 0xb0b32b20: ver 3 0 (tinfo 0xa75032b0) E/flutter (12905): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception: E/flutter (12905): WebSocketChannelException: WebSocketChannelException: HttpException: Invalid response line, uri = http://192.168.1.22:1024 E/flutter (12905): #0 new IOWebSocketChannel._withoutSocket. (package:web_socket_channel/io.dart:83:24) E/flutter (12905): #1 _invokeErrorHandler (dart:async/async_error.dart:13:29) E/flutter (12905): #2 _HandleErrorStream._handleError (dart:async/stream_pipe.dart:286:9) E/flutter (12905): #3 _ForwardingStreamSubscription._handleError (dart:async/stream_pipe.dart:168:13) E/flutter (12905): #4 _RootZone.runBinaryGuarded (dart:async/zone.dart:1328:10) E/flutter (12905): #5 _BufferingStreamSubscription._sendError.sendError (dart:async/stream_impl.dart:355:15) E/flutter (12905): #6 _BufferingStreamSubscription._sendError (dart:async/stream_impl.dart:373:16) E/flutter (12905): #7 _BufferingStreamSubscription._addError (dart:async/stream_impl.dart:272:7) E/flutter (12905): #8 _SyncStreamController._sendError (dart:async/stream_controller.dart:767:19) E/flutter (12905): #9 _StreamController._addError (dart:async/stream_controller.dart:647:7) E/flutter (12905): #10 _RootZone.runBinaryGuarded (dart:async/zone.dart:1328:10) E/flutter (12905): #11 _BufferingStreamSubscription._sendError.sendError (dart:async/stream_impl.dart:355:15) E/flutter (12905): #12 _BufferingStreamSubscription._sendError (dart:async/stream_impl.dart:373:16) E/flutter (12905): #13 _BufferingStreamSubscription._addError (dart:async/stream_impl.dart:272:7) E/flutter (12905): #14 _SyncStreamController._sendError (dart:async/stream_controller.dart:767:19) E/flutter (12905): #15 _StreamController._addError (dart:async/stream_controller.dart:647:7) E/flutter (12905): #16 new Stream.fromFuture. (dart:async/stream.dart:110:18) E/flutter (12905): #17 _RootZone.runBinary (dart:async/zone.dart:1386:54) E/flutter (12905): #18 _FutureListener.handleError (dart:async/future_impl.dart:143:20) E/flutter (12905): #19 Future._propagateToListeners.handleError (dart:async/future_impl.dart:650:47) E/flutter (12905): #20 Future._propagateToListeners (dart:async/future_impl.dart:671:24) E/flutter (12905): #21 Future._completeError (dart:async/future_impl.dart:490:5) E/flutter (12905): #22 Future._asyncCompleteError. (dart:async/future_impl.dart:538:7) E/flutter (12905): #23 _microtaskLoop (dart:async/schedule_microtask.dart:41:21) E/flutter (12905): #24 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5) Application finished.

NTMS2017 commented 6 years ago

After I connect the server;

I send this: Q101::49785::*****

and I will get this 1::2::119351:_:NİYAZİ TOROS

NTMS2017 commented 6 years ago

I try to test and find where is the error coming from. And I found that data that I send to socket is not correct:

Q: 28.06.2018 08:53:57->GET / HTTP/1.1. (correct send data but be: Q101::49785::ABCDE) A: 28.06.2018 08:53:57 ->:1::1::FAIL1

So how can I emit GET / HTTP/1.1. not to send to server?

I create a Flutter App. I need to connect my app to local network socket services. As shown below, I can use telnet Connect, Send data and Receive data from server. I use Flutter web_socket plugin and example. I can connect to server and send the data but I cannot catch (or get data, it dosen't show anything.) the data. In Flutter google groups one person advice me to use stream instead of StreamBuilder.

To send data I use; Q101::49785::ABCDE And receive data I get; 1::2::119351:_:NİYAZİ TOROS

And when I use this example (https://flutter.io/cookbook/networking/web-sockets/) I am getting error on my socket service as:

Q: 28.06.2018 08:53:57->GET / HTTP/1.1 A: 28.06.2018 08:53:57 ->:1::1::FAIL1

Example: Last login: Tue Jun 26 15:01:44 on ttys000 Niyazis-MBP:~ niyazitoros$ telnet telnet> telnet 192.168.1.22 1024 Trying 192.168.1.22... Connected to 192.168.1.22. Escape character is '^]'. Q101::49785::***** 1::2::119351:_:NİYAZİ TOROS