Git Product home page Git Product logo

flutter_socket_io's Introduction

adhara_socket_io

socket.io for flutter by adhara

supports both Android and iOS

Usage:

See example/lib/main.dart for better example

    SocketIOManager manager = SocketIOManager();
    SocketIO socket = manager.createInstance('http://192.168.1.2:7000/');       //TODO change the port  accordingly
    socket.onConnect((data){
      print("connected...");
      print(data);
      socket.emit("message", ["Hello world!"]);
    });
    socket.on("news", (data){   //sample event
      print("news");
      print(data);
    });
    socket.connect();
    ///disconnect using
    ///manager.

To request callback on ack:

  socket.emitWithAck("message", ["Hello world!"]).then( (data) {
    // this callback runs when this specific message is acknowledged by the server
    print(data);
  });

Running example:

  1. Open example/ios in XCode or example/android in android studio. Build the code once (cd example & flutter build apk | flutter build ios --no-codesign)

  2. cd example/socket.io.server

    1 run npm i

    2 run npm start

  3. open example/lib/main.dart and edit the URI in #7 to point to your hosted/local socket server instances as mentioned step 2

    For example:

    const String URI = "http://192.168.1.2:7000/";
    const String URI = "http://mysite.com/";
  4. run Android/iOS app

iOS support ๐Ÿ“ข๐Ÿ“ข

This project uses Swift for iOS support, please enable Swift support for your project for this plugin to work

Android support for SDK > 27

Configure android:usesCleartextTraffic="true" as a property of <application ...> tag in android/app/src/main/AndroidManifest.xml

For example:

<application
        android:name="io.flutter.app.FlutterApplication"
        android:label="adhara_socket_io_example"
        android:usesCleartextTraffic="true"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"...>...</activity>

Refer to discussion here

Other Packages:

Feel free to checkout our Adhara package

flutter_socket_io's People

Contributors

alexhimik avatar aurbina83 avatar brooth avatar henrikthien avatar lhcdims avatar saifallak avatar tiholic avatar vardiak avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.