connecta 1.2.0 copy "connecta: ^1.2.0" to clipboard
connecta: ^1.2.0 copied to clipboard

Simplify and streamline socket communication in Dart applications

example/main.dart

import 'dart:developer';

import 'package:connecta/connecta.dart';

Future<void> main() async {
  final connecta = Connecta(
    ConnectaToolkit(
      hostname: 'example.org',
      port: 5222,
      connectionType: ConnectionType.upgradableTcp,
    ),
  );

  await connecta.connect(
    ConnectaListener(onData: (data) async => _handleData(connecta, data)),
  );
  connecta.send(
    "<stream:stream to='example.org' xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client' xml:lang='en' version='1.0'>",
  );
}

Future<void> _handleData(
  Connecta connecta,
  List<int> data,
) async {
  final rawData = String.fromCharCodes(data);
  if (rawData.contains(
    "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'><required/></starttls>",
  )) {
    connecta.send('<starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls" />');
  } else if (rawData == "<proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>") {
    await connecta.upgradeConnection(
      listener:
          ConnectaListener(onData: (data) => log(String.fromCharCodes(data))),
    );

    connecta.send(
      "<stream:stream to='example.org' xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client' xml:lang='en' version='1.0'>",
    );
  }
}
1
likes
160
pub points
37%
popularity

Publisher

verified publishervsevex.me

Simplify and streamline socket communication in Dart applications

Repository (GitHub)
View/report issues

Topics

#network #tls #tcp #wrapper

Documentation

API reference

License

MIT (license)

More

Packages that depend on connecta