A LAN Communication Flutter Package Based Off Node Commander

A LAN Communication Flutter Package Based Off Node Commander

A LAN communication Flutter package based off Node Commander but removing parts such as Commander Nodes and making communication between client and server two way.

client_server_lan

A LAN communication Flutter package based off Node Commander but removing parts such as Commander Nodes and making communication between client and server two way.

Usage

Add to android files

In android/app/AndroidManifest

<application ...
  android:networkSecurityConfig="@xml/network_security_config" >

 <meta-data android:name="io.flutter.network-policy"
        android:resource="@xml/network_security_config"/>

Then create a folder xml inside create a file: network_security_config.xml

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
  <base-config cleartextTrafficPermitted="true">
     <trust-anchors>
        <certificates src="system" />
    </trust-anchors>
  </base-config>
 </network-security-config>

Run a Node

Start a Server Node

import 'dart:async';
import 'package:client_server_lan/client_server_lan.dart';
ServerNode server;
void startServer() async {
    server = ServerNode(
      name: "server_name",//any text name
      verbose: true,//output for debugging purposes
      onDispose: onDispose,//function run on server disposed
      clientDispose: clientDispose,//function run on client dispose
    );
    await server.init();
    await server.onReady;
    setState(() {
      serverStatus = "Server ready on ${server.host}:${server.port}";
    });
    server.dataResponse.listen((DataPacket data) {
      setState(() {
        String dataReceived = data.payload;
      });
    });

Start a Client Node

import 'dart:async';
import 'package:client_server_lan/client_server_lan.dart';
ClientNode client;
void startClient() async {
    client = ClientNode(
      name: clientName,//any text name
      verbose: true,//output for debugging purposes
      onDispose: onDispose,//function run on client dispose
    );
    await client.init();
    await client.onReady;
    setState(() {
      clientStatus = "Client ready on ${client.host}:${client.port}";
    });
    client.dataResponse.listen((DataPacket data) {
      setState(() {
        String dataReceived = data.payload;
      });
    });
  }

Server scan for Clients

void findClients() async {
    server.discoverNodes();
    await Future<Object>.delayed(const Duration(seconds: 2));
    //outputs client names and IPs (not neccessary)
    setState(() {
      clientIPs = "";
    });
    for (final s in server.clientsConnected) {
      setState(() {
        clientIPs += "id=${s.name},IP=${s.address}\n";
      });
    }
  }

Transfer Data

WARNING: Data not excepted with titles in client.internalTitles/server.internalTitles

Transfer from Client to Server

void clientToServer(String dataToSend) async {
    await client.sendData(dataToSend, "userInfo");
  }

Transfer from Server to Client

void serverToClient(String dataToSend, String clientName) async {
    final String client = server.clientUri(clientName);
    await server.sendData(dataToSend, "userInfo", client);
  }

Example

New Example app courtesy of Fikrirazzaq

Example

Download Details:

Author: Robert3141

Source Code: https://github.com/Robert3141/client_server_lan

flutter dart mobile-apps

What is Geek Coin

What is GeekCash, Geek Token

Best Visual Studio Code Themes of 2021

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Google's Flutter 1.20 stable announced with new features - Navoki

Google has announced new flutter 1.20 stable with many improvements, and features, enabling flutter for Desktop and Web

Top 25 Flutter Mobile App Templates in 2020

Flutter has been booming worldwide from the past few years. While there are many popular mobile app development technologies out there, Flutter has managed to leave its mark in the mobile application development world. In this article, we’ve curated the best Flutter app templates available on the market as of July 2020.

Flutter App Development Trends 2020

As the new decade dawns upon us, a slew of technologies has been making a lot of noise to grab the developers’ attention. While native app development is going strong, the trade winds are now blowing towards going cross-platform.

How To Succeed In Mobile App Wireframe Design?

This article covers everything about mobile app wireframe design: what to do and what not, tools used in designing a mobile or web app wireframe, and more.

Improve your mobile app with Mobile App Maintenance

Nevina infotech is leading mobile app maintenance and support service provider company. Our expertise in mobile app maintenance and upgrade services for android and iOS application, to keep your app updated, secure, bug free and driving revenue.