fennec_socket_io_server is dart plugin to implement SOCKET IO for the server side. it belongs to fennec framework pub.dev but it can be used separately.

Installation

install the plugin from pub.dev

Example with own HTTP Server.

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

await serverIO1.listen('0.0.0.0', 3000);

Example with Fennec HTTP Server.

 Application application = Application();
 ServerIO serverIO = ServerIO();
 application.setPort(8000).setHost(InternetAddress.loopbackIPv4);
 application.get(
     path: '/dynamic_routes/@userId',
     requestHandler: (req, res) {
       serverIO.emit('fromServer', DateTime.now().toIso8601String());
       res.json({'userId': req.pathParams['userId']});
     },
     middlewares: []);

 Router testRouter = Router(routerPath: '/v1/api');
 testRouter.get(
     path: '/simple', requestHandler: TestController().test, middlewares: []);
 testRouter.get(
   path: '/simple1',
   requestHandler: (Request req, Response res) {
     serverIO.emit('message', 'hello fennec');
     res.send('ss');
   },
 );
serverIO.on('connection', (client) {
print('coo');
});
application.useWebSocket(true);
application.addRouter(testRouter);
application.socketIO(socketIOHandler: (context, ws) {
streamController.sink.add(ws);
});
await serverIO.listenToHttpServer(streamController);
await application.runServer();




License

MIT