Dart
Dart
Send Bytes on a Socket Connection
See more Socket/SSL/TLS Examples
Demonstrates how to send a mixture of binary (non-text) and text bytes on a socket connection.Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
final socket = CkSocket();
// Connect to some host:port
final ssl = false;
final maxWaitMillisec = 20000;
final port = 5555;
try {
socket.connect('test.com', port, ssl, maxWaitMillisec);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// We wish to send a 0x00 byte followed by the us-ascii string "10800"
final bd = CkBinData();
bd.appendByte(0);
bd.appendString('10800', 'utf-8');
// Send the entire contents of bd.
try {
socket.sendBd(bd, 0, 0);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
}