tcp_header 1.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 52

tcp_header #

A simple way to prevent TCP socket from splitting your data into random chunks

Getting Started #

This project is a starting point for a Dart package, a library module containing code that can be shared easily across multiple Flutter or Dart projects.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

[1.0.1] - Added decoder class #

[1.0.0] - Initial release #

example/example.dart

import 'dart:typed_data';

import 'package:tcp_header/tcp_header.dart';

Uint8List buffer = Uint8List(0);
bool sanityChecked = false;

void onReceiveDataFromTCPSocket(final List<int> data){
  buffer = Uint8List.fromList(buffer.followedBy(data).toList());

  if(!sanityChecked){
    if(headerCanBeExtracted(data)){
      final int messageLength = lengthHeaderFromData(data);
      if(messageLength > 0xFFFFFF+1){ //if the client intends to send more than 16 megabytes
        //socket.destroy();
      } else {
        sanityChecked = true;
      }
    }
  }

  if(dataWithTCPHeaderCanBeDecoded(buffer)){
    final Uint8List allBytes = dataFromDataWithTCPHeader(buffer);
    //work(allBytes);
    buffer = Uint8List(0);
  } else {
    //wait for another chunk of data
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  tcp_header: ^1.0.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:tcp_header/tcp_header.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
5
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
52
Learn more about scoring.

We analyzed this package on Apr 7, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

Health issues and suggestions

Document public APIs. (-1 points)

11 out of 11 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Format lib/tcp_header.dart.

Run dartfmt to format lib/tcp_header.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
Dev dependencies
test ^1.9.3