Navigation

    SmartAPI Forum
    • Register
    • Login
    • Search
    • Categories
    • Popular
    • Groups
    • FAQs
    • API Docs

    How can i use this with dart(flutter)?

    General Discussion
    3
    12
    83
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • 9
      91priyansh last edited by 91priyansh

      @admin i am getting encoded data from web-socket. i am using dart(flutter). do you know y this is happening? if you have any ref for dart(flutter) it would be great..

      James Bond 1 Reply Last reply Reply Quote 0
      • 9
        91priyansh last edited by

        @admin i am getting data from like this eJyLrlZKzFayUsrPVtJRKkksBrGT84Ds3OJ0EDM/Ly81uSQ1Rak2FgAaGQ1z and eJyLjgUAARUAuQ==. Is there issue from client_side? if any one knows tell me solution?

        1 Reply Last reply Reply Quote 0
        • James Bond
          James Bond @91priyansh last edited by James Bond

          @91priyansh
          How you accessing WebSocket ? By using official SDK's or by using pure WebSocket protocol and HTTP ?

          Also share your code here to get more help.

          “Bond. James Bond.”

          9 1 Reply Last reply Reply Quote 0
          • James Bond
            James Bond @91priyansh last edited by

            @91priyansh
            Dart / Flutter is not officially supported. But you can use any officially supported SDK and further use it in your app.

            “Bond. James Bond.”

            S 1 Reply Last reply Reply Quote 0
            • S
              Surya 1 @James Bond last edited by

              @James-Bond

              You can also edit you posts and add more.. You can click on three dots and edit your post.

              you are always making doubles posts within seconds. Please keep the threads uncluttered..

              James Bond 2 Replies Last reply Reply Quote 0
              • James Bond
                James Bond @Surya 1 last edited by James Bond

                @rajanprabu
                Ok, I'll consider this next time.

                Earlier, sometimes this happened due to 3600 sec (1hr) limit. Sometimes I had to add more points later when it come to my mind, but this limit won't let me to do it. 🙄

                “Bond. James Bond.”

                1 Reply Last reply Reply Quote 0
                • James Bond
                  James Bond @Surya 1 last edited by James Bond

                  @rajanprabu
                  No offence but if you closely look, you will get idea of why I'm creating multiple posts. I'm replying to particular post of questioner not creating double posts, because mostly on this forum, people who ask questions are either novice or they have no experience at all. So if I add everything in one post it confuse them further.

                  “Bond. James Bond.”

                  1 Reply Last reply Reply Quote 0
                  • 9
                    91priyansh @James Bond last edited by 91priyansh

                    @James-Bond i am using web_socket_channel dart(package) to access websocket. here is my code

                    //in dart

                    void connectToWS() {
                    try {
                    channel = IOWebSocketChannel.connect(Uri.parse(
                    'wss://omnefeeds.angelbroking.com/NestHtml5Mobile/socket/stream'));

                        channel.stream.listen((message) {
                        print("Message $message");
                      }, onError: (error) {
                        print(error);
                      });
                      
                     
                      var reqJson = {
                        "task": "cn",
                        "channel": "",
                        "token": "token",
                        "user": "clientId",
                        "acctid": "clientId"
                      };
                    
                      var req = jsonEncode(reqJson);
                    
                      channel.sink.add(req);
                    
                      //
                      print("Sent connection request message");
                    } catch (e) {
                      print(e);
                    }
                    //
                    

                    }

                    1 Reply Last reply Reply Quote 0
                    • C
                      civi last edited by

                      Can anyone help me to decode response in flutter?

                      1 Reply Last reply Reply Quote 0
                      • C
                        civi @91priyansh last edited by

                        @91priyansh I've done this (decoded successfully) check here https://smartapi.angelbroking.com/topic/1887/how-to-decode-web-socket-response-in-flutter-dart

                        1 Reply Last reply Reply Quote 0
                        • C
                          civi last edited by

                          import 'dart:convert';
                          import 'dart:io';
                          import 'package:flutter/material.dart';
                          import 'package:web_socket_channel/web_socket_channel.dart';

                          class ScreenAngelWebSocket extends StatefulWidget {
                          const ScreenAngelWebSocket({Key? key}) : super(key: key);

                          @override
                          State<ScreenAngelWebSocket> createState() => _ScreenAngelWebSocketState();
                          }

                          class _ScreenAngelWebSocketState extends State<ScreenAngelWebSocket> {
                          WebSocketChannel? channel;

                          @override
                          void initState() {
                          super.initState();
                          channel = WebSocketChannel.connect(Uri.parse(ApiPath.WSS_ANGEL));
                          channel!.sink.add(
                          jsonEncode({
                          "task": "cn",
                          "channel": "",
                          "token": "feed_token",
                          "user": "client_id",
                          "acctid": "client_id"
                          }),
                          );

                          channel!.sink.add(
                          jsonEncode({
                          "task": "mw",
                          // "channel": "nse_cm|3045",
                          "channel": "nse_cm|3045&nse_cm|2885", // SBI & Reliance
                          "token": "feed_token",
                          "user": "client_id",
                          "acctid": "client_id"
                          }),
                          );
                          channel!.stream.listen(
                          (data) {
                          String response = data.toString();
                          debugPrint('wss Response before Decode: ' + response);
                          var step1 = base64.decode(response);
                          debugPrint('wss Response Decode Step 1: ' + step1.toString());
                          var inflated = zlib.decode(step1);
                          var step2 = utf8.decode(inflated);
                          debugPrint('wss Response Decode Step 2: ' + step2.toString());

                          var step3 = json.decode(step2);
                          debugPrint('wss Response Decode Step 3: ' + step3.toString());

                          if (step3.toString().contains('task') &&
                          step3[0]['task'].toString() == 'cn' &&
                          step3[0]['msg'].toString() == 'cn') {
                          debugPrint('wss Socket Connected');
                          }
                          },
                          onDone: () {
                          debugPrint('wss Socket Connected');
                          },
                          onError: (error) => debugPrint('wss Error: ' + error.toString()),
                          );
                          }

                          @override
                          void dispose() {
                          super.dispose();
                          channel!.sink.close();
                          }

                          @override
                          Widget build(BuildContext context) {
                          return Column(
                          mainAxisSize: MainAxisSize.max,
                          crossAxisAlignment: CrossAxisAlignment.stretch,
                          children: [
                          Text('Web Socket Demo'),
                          ],
                          );
                          }
                          }

                          Decoded Data in Log

                          wss Response Decode Step 3: [{e: nse_cm, name: sf, ltp: 2597.25, ltq: 20, tk: 2885, ltt: NA}, {e: nse_cm, name: sf, ltp: 518.90, ltq: 8, tk: 3045, ltt: NA}]

                          Also find answer here https://smartapi.angelbroking.com/topic/1887/how-to-decode-web-socket-response-in-flutter-dart/2

                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post