typed_event_emitter 1.0.0 copy "typed_event_emitter: ^1.0.0" to clipboard
typed_event_emitter: ^1.0.0 copied to clipboard

Simple package to emit and control events

example/typed_event_emitter_example.dart

import 'dart:async';
import 'dart:developer';

import 'server.dart';
import 'server_event.dart';

void main() {
  final server = Server();

  server.handle<ServerOnStartEvent>((event) {
    print('Server started');
  });

  server.handle<ServerOnStopEvent>((event) {
    print('Server stopped');
  });

  server.handle<ServerOnClientConnectedEvent>((event) {
    print('client with name "${event.clientId}" was connected');
  });

  server.handle<ServerOnClientDisconnectedEvent>((event) {
    print('client with name "${event.clientId}" was disconnected');
  });

  server.handle<ServerOnErrorEvent>((event) {
    log(event.message, error: event.error, stackTrace: event.stackTrace);
  });

  server.handle<ServerOnDataEvent>((event) {
    print('data received from client "${event.clientId}"');
    print('data: ${String.fromCharCodes(event.data)}');
  });

  server.handle<ServerOnSendDataEvent>((event) {
    print('send data: ${String.fromCharCodes(event.data)}');
  });

  server.start();

  server.addClient('My Client');

  server.send("Hello World");

  // wait to receive data from client then stop / destroy server
  Timer(const Duration(seconds: 7), () {
    server.destroy();
  });
}
0
likes
140
points
24
downloads

Publisher

unverified uploader

Weekly Downloads

Simple package to emit and control events

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

More

Packages that depend on typed_event_emitter