fennec_socket_io_server 0.0.5 copy "fennec_socket_io_server: ^0.0.5" to clipboard
fennec_socket_io_server: ^0.0.5 copied to clipboard

this plugin belongs to Fennec Framework. it can be used to implement a performant realtime connection from server side.

example/example.dart

import 'dart:async';
import 'dart:io';

import 'package:fennec/fennec.dart';
import 'package:fennec_socket_io_server/server_io.dart';

void main(List<String> arguments) async {
  /// Connect SOCKET IO Server with Fennec HTTP Server
  StreamController<HttpRequest> streamController = StreamController();
  Application application = Application();
  application.setNumberOfIsolates(1);
  List<dynamic> clients = [];
  ServerIO serverIO = ServerIO();
  ServerIO serverIO1 = ServerIO();
  application.setPort(8000).setHost('0.0.0.0');
  application.get(
    path: '/dynamic_routes/@userId',
    requestHandler: (context, req, res) {
      serverIO.emit('fromServer', DateTime.now().toIso8601String());
      return res.ok(body: {'userId': req.pathParams['userId']}).json();
    },
  );

  Router testRouter = Router(routerPath: '/v1/api');

  testRouter.get(
    path: '/simple1',
    requestHandler: (ServerContext context, Request req, Response res) {
      for (var i = 0; i < 7; i++) {
        serverIO.emit('message', 'JACK AISSA');
      }
      serverIO1.emit('message', 'JACK AISSA');
      return res.ok(body: 'ss');
    },
  );

  application.useWebSocket(true);
  application.addRouter(testRouter);
  application.socketIO(socketIOHandler: (context, ws) {
    streamController.sink.add(ws);
  });
  await serverIO.listenToHttpServer(streamController);
  await application.runServer();

  /// run SOCKET IO Server as own Server

  serverIO1.on('connection', (client) {
    print('connection');
    serverIO1.emit('fromServer', 'ok');
  });

  await serverIO1.listen('0.0.0.0', 3000);
}
12
likes
130
pub points
20%
popularity

Publisher

verified publisherfennecframework.com

this plugin belongs to Fennec Framework. it can be used to implement a performant realtime connection from server side.

Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (LICENSE)

Dependencies

uuid

More

Packages that depend on fennec_socket_io_server