Issue in client socket in connecting and receiving server socket data.

438 views
Skip to first unread message

Sridhar Parida

unread,
Aug 4, 2020, 9:21:44 PM8/4/20
to Flutter Development (flutter-dev)
Hi,
I am running a google map app. which sending map data from server via socket. But issue in receiving data at client end. The code is below; Need urgent help.

_connecSocket() {
    socket = SocketIOManager().createSocketIO(
        'http://localhost:8081', '/data-info',
        socketStatusCallback: _socketStatus);

    socket.init();
    // socket.subscribe("/info/values", _onSocketInfo);

    socket.connect();
  }

  _onSocketInfo(dynamic data) {
    print("Socket info: " + data);
  }

Regards,
Sridhar

Suzuki Tomohiro

unread,
Aug 4, 2020, 11:00:03 PM8/4/20
to Sridhar Parida, Flutter Development (flutter-dev)
Can you describe the issue in more detail?

Error message?

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/fcff08f2-b0ee-496c-9862-c49b1382a627n%40googlegroups.com.

Sridhar Parida

unread,
Aug 5, 2020, 12:39:47 AM8/5/20
to Suzuki Tomohiro, Flutter Development (flutter-dev)
Hi Suzuki,
I have shared the Java Server build ( via gmail drive sharing ). the jar file can be run using >java jar socket-map.jar.
The client as below;

The client socket  is not connecting. I need to connect and receive the data from Server.

import 'package:flutter/material.dart';
import 'package:flutter_socket_io/flutter_socket_io.dart';
import 'package:flutter_socket_io/socket_io_manager.dart';
import 'package:web_socket_channel/io.dart';
import 'package:web_socket_channel/status.dart' as status;

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  SocketIO socket;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  // _connecSocket() async {
  //   var channel = IOWebSocketChannel.connect("http://localhost:8081/data-info");

  //   channel.stream.listen((message) {
  //     channel.sink.add("received!");
  //     channel.sink.close(status.goingAway);
  //   });
  // }

  _connecSocket() {
    socket = SocketIOManager().createSocketIO(
        'http://localhost:8081''/data-info',        
        socketStatusCallback: _socketStatus);

    socket.init();
     socket.subscribe("/info/values", _onSocketInfo);

    socket.connect();
  }

  _onSocketInfo(dynamic data) {
    print("Socket info: " + data);
  }

  _socketStatus(dynamic data) {
    print("Socket status: " + data);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: RaisedButton(
          child: Text('Hello'),
          onPressed: () {
            _connecSocket();
            print('working');
          },
        ),
      ),
    );
  }
}

Regards,
Sridhar

Suzuki Tomohiro

unread,
Aug 5, 2020, 9:04:40 AM8/5/20
to Flutter Development (flutter-dev)
I don’t see any error message. Which line of the log is unexpected to you?

On Wed, Aug 5, 2020 at 08:03 Sridhar Parida <spa...@asiczen.com> wrote:
Hi Suzuki San,
Shared the client file having issue.

The log file as below;
================
Launching lib\main.dart on SM G610F in debug mode...
√ Built build\app\outputs\apk\debug\app-debug.apk.
Connecting to VM Service at ws://127.0.0.1:57407/gOwiHWrJT8w=/ws
D/libGLESv2(10014): STS_GLApi : DTS, ODTC are not allowed for Package : com.example.socket_project
D/ViewRootImpl@6e4f022[MainActivity](10014): ViewPostIme pointer 0
D/ViewRootImpl@6e4f022[MainActivity](10014): ViewPostIme pointer 1
I/flutter (10014): CREATING NEW SOCKET: http://localhost:8081/data-info
I/flutter (10014): Created+++++++++++
I/flutter (10014): working
D/FlutterSocketIoPlugin: FlutterSocketIoPlugin(10014): onMethodCall: socketInit - domain: http://localhost:8081 - with namespace: /data-info
D/FlutterSocketIoPlugin: TOTAL SOCKETS: (10014): 0
D/FlutterSocketIoPlugin: TOTAL SOCKETS: (10014): 0
D/FlutterSocketIoPlugin: added SocketIO(10014): http://localhost:8081/data-info
D/FlutterSocketIoPlugin: SocketIO(10014): connecting...null
D/ViewRootImpl@6e4f022[MainActivity](10014): ViewPostIme pointer 0
D/ViewRootImpl@6e4f022[MainActivity](10014): ViewPostIme pointer 1
I/zygote  (10014): Do partial code cache collection, code=22KB, data=30KB
I/zygote  (10014): After code cache collection, code=22KB, data=30KB
I/zygote  (10014): Increasing code cache capacity to 128KB
I/flutter (10014): Created+++++++++++
I/flutter (10014): working
D/FlutterSocketIoPlugin: FlutterSocketIoPlugin(10014): onMethodCall: socketInit - domain: http://localhost:8081 - with namespace: /data-info
D/FlutterSocketIoPlugin: TOTAL SOCKETS: (10014): 1
D/FlutterSocketIoPlugin: SocketIOManager(10014): socket: http://localhost:8081/data-info already existed!
================


Regards,
Sridhar.

On Wed, Aug 5, 2020 at 10:11 AM Sridhar Parida <spa...@asiczen.com> wrote:
Hi Suzuki San,

Shared the server ( .jar ) link.


Regards,
Sridhar.

 

Suzuki Tomohiro

unread,
Aug 5, 2020, 10:11:01 AM8/5/20
to Flutter Development (flutter-dev), Sridhar Parida
(Last question)
I don’t see any error message. Which line of the log is unexpected to you?
On Wed, Aug 5, 2020 at 09:55 Sridhar Parida <spa...@asiczen.com> wrote:
Launching lib\main.dart on SM G610F in debug mode...
√ Built build\app\outputs\apk\debug\app-debug.apk.
Connecting to VM Service at ws://127.0.0.1:59598/mtWv_zPlLJ8=/ws
D/libGLESv2(12134): STS_GLApi : DTS, ODTC are not allowed for Package : com.example.socket_project
D/ViewRootImpl@6e4f022[MainActivity](12134): ViewPostIme pointer 0
D/ViewRootImpl@6e4f022[MainActivity](12134): ViewPostIme pointer 1
I/flutter (12134): CREATING NEW SOCKET: localhost:8081/data-info
I/flutter (12134): Created+++++++++++
I/flutter (12134): working
D/FlutterSocketIoPlugin: FlutterSocketIoPlugin(12134): onMethodCall: socketInit - domain: localhost:8081 - with namespace: /data-info
D/FlutterSocketIoPlugin: TOTAL SOCKETS: (12134): 0
D/FlutterSocketIoPlugin: TOTAL SOCKETS: (12134): 0
D/FlutterSocketIoPlugin: added SocketIO(12134): localhost:8081/data-info
D/FlutterSocketIoPlugin: SocketIO(12134): connecting...null
D/ViewRootImpl@6e4f022[MainActivity](12134): ViewPostIme pointer 0
D/ViewRootImpl@6e4f022[MainActivity](12134): ViewPostIme pointer 1
D/ViewRootImpl@6e4f022[MainActivity](12134): ViewPostIme pointer 0
D/ViewRootImpl@6e4f022[MainActivity](12134): ViewPostIme pointer 1
I/flutter (12134): Created+++++++++++
I/flutter (12134): working
D/FlutterSocketIoPlugin: FlutterSocketIoPlugin(12134): onMethodCall: socketInit - domain: localhost:8081 - with namespace: /data-info
D/FlutterSocketIoPlugin: TOTAL SOCKETS: (12134): 1
D/FlutterSocketIoPlugin: SocketIOManager(12134): socket: localhost:8081/data-info already existed!
I/zygote  (12134): Do partial code cache collection, code=26KB, data=30KB
I/zygote  (12134): After code cache collection, code=26KB, data=30KB
I/zygote  (12134): Increasing code cache capacity to 128KB
V/InputMethodManager(12134): Starting input: tba=android.view.inputmethod.EditorInfo@65e6234 nm : com.example.socket_project ic=null
D/InputMethodManager(12134): startInputInner - Id : 0
I/InputMethodManager(12134): startInputInner - mService.startInputOrWindowGainedFocus
D/InputTransport(12134): Input channel constructed: fd=91
D/InputTransport(12134): Input channel destroyed: fd=86
D/SurfaceView(12134): windowStopped(true) false 9bb0870 of ViewRootImpl@6e4f022[MainActivity]
D/SurfaceView(12134): BG show() Surface(name=Background for - SurfaceView - com.example.socket_project/com.example.socket_project.MainActivity@9bb0870@0) io.flutter.embedding.android.FlutterSurfaceView{9bb0870 V.E...... ........ 0,0-1080,1920}
D/SurfaceView(12134): surfaceDestroyed 1 #1 io.flutter.embedding.android.FlutterSurfaceView{9bb0870 V.E...... ........ 0,0-1080,1920}

Suzuki Tomohiro

unread,
Aug 6, 2020, 8:08:30 AM8/6/20
to Flutter Development (flutter-dev)
Good. Further questions:

Where is “Created+++++++++++” in the log coming from? Is that your code?

How do you know socket.init() is not processed?

On Thu, Aug 6, 2020 at 00:52 Sridhar Parida <spa...@asiczen.com> wrote:
After socket is created, 
1. the control is not proceeding for socket.init() and socket.connect().
2. Even though subscribe for the data ( 2 Vehicle no. and Geo coordinates from server ) not able to receive at client side (  there may be some error in "main.dart" file and I am unable to identify.

Regards,
Sridhar

Sridhar Parida

unread,
Aug 6, 2020, 11:44:48 PM8/6/20
to Suzuki Tomohiro, Flutter Development (flutter-dev)
Below is my Code. The print after socket create; socket.init and socket.connect not printed. Also the socket data not printed.

=========================================

class _MyHomePageState extends State<MyHomePage> {
  SocketIO socket;
 
  @override
  void initState() {
    super.initState();
  }

  _connecSocket() async {

    socket = SocketIOManager().createSocketIO('http://localhost:8081', '/data-info', socketStatusCallback: _socketStatus);
    print('Created+++++++++++');  
    await socket.init();
    print('Initialized++++++++++++');
    await socket.connect();
    await Future.delayed(Duration(seconds: 15));
    print('Connected+++++++=');

if (socket != null)
{
 socket.subscribe('/info/values', (data) async {
 print("Status+++++++++++++++++ "+ data.body);
});
}
else
{
  print('Socket not Connected');
}

}

=====================
Regards,
Sridhar


Suzuki Tomohiro

unread,
Aug 7, 2020, 12:29:41 AM8/7/20
to Sridhar Parida, Flutter Development (flutter-dev)
Any chance that socket.init() is throwing an exception? Use try-catch clause to confirm this.

Reply all
Reply to author
Forward
0 new messages