This library was built to facilitate the use of WebSocket and Socket, both client and server. For that, the same interface was created and the necessary implementations were carried out using dart:io and dart:html.

In this way it is possible to program for web and android (for example), with the same code, without worrying about importing dart:html for io devices.

Example

final server = await KsSocketServer.bind(ipHost, ipPort);

server.listerConnection((clientAction) => clientAction.copyWith(
    listerMessage: (message, data) {
        print('listerMessage: $data');
    },
    onClose: (message) {
        print('onClose');
    },
    onConnection: (_) => print('New Connection'),
));


final client = await KsSocket.connect(ipHost, ipPort);

client.send('Hello'));
client.send({
    'id': 1005,
    'user': 'name',
}));
await Future.delayed(const Duration(seconds: 1));
await client.close();

Upcoming Versions:

  • Implement the WebSocket server;
  • Create unit tests;
  • Develop a test application;

Additional information

Feel Free to request any missing features or report issues here.

Libraries

ks_websocket