Sample code for 30+ languages & platforms
Dart

Duplicate a Socket Wrapper Sharing the Connection

See more Socket/SSL/TLS Examples

Demonstrates Socket.DupSocket, which populates a destination Socket with another wrapper that shares this object's underlying connection.

Background. The shared connection is reference-counted, and all wrappers operate on the same live connection. The destination first releases any connection it previously held.

Chilkat Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

void main() {
  final socket = CkSocket();

  // Connect to the server using TLS.
  final bTls = true;
  final maxWaitMs = 5000;
  try {
    socket.connect('example.com', 5000, bTls, maxWaitMs);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  // Create a second Socket wrapper that shares this object's underlying connection.  Both wrappers
  // operate on the same live connection; the shared connection is reference-counted.
  final dupSock = CkSocket();
  try {
    socket.dupSocket(dupSock);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  print('Duplicate socket wrapper created.');
}