client_server_lan 2.0.0 copy "client_server_lan: ^2.0.0" to clipboard
client_server_lan: ^2.0.0 copied to clipboard

outdated

A simple to use LAN communication package. The Server and a Client can freely distribute data over LAN.

client_server_lan #

Pub Documentation

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.

ONLY SUPPORTS ANDROID AT THE MOMENT!!!

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:wifi/wifi.dart';
import 'package:client_server_lan/client_server_lan.dart';
void startServer() async {
    String ip = await Wifi.ip;
    server = ServerNode(
      name: "Server",
      verbose: true,
      host: ip,
      port: 8085,
    );
    await server.init();
    await server.onReady;
    setState(() {
      serverStatus = "Server ready on ${server.host}:${server.port}";
    });
    server.dataResponse.listen((DataPacket data) {
      setState(() {
        dataRecieved = data.payload;
      });
    });
  }

Start a Client Node

void startClient() async {
    dropdownEnabled = false;
    String ip = await Wifi.ip;
    client = ClientNode(
      name: "Client Node",
      verbose: true,
      host: ip,
      port: 8085,
    );
    await client.init();
    await client.onReady;
    setState(() {
      clientStatus = "Client ready on ${client.host}:${client.port}";
    });
    client.dataResponse.listen((DataPacket data) {
      setState(() {
        dataRecieved = data.payload;
      });
    });
  }

Server scan for Clients

void findClients() async {
    server.discoverNodes();
    await Future<Object>.delayed(const Duration(seconds: 2));
    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() async {
    await client.sendData("userInfo",dataToSend, client.serverDetails.address);
  }

Transfer from Server to Client

void serverToClient(String clientName) async {
    final String client = server.clientUri(clientName);
    await server.sendData("userInfo",dataToSend, client);
  }
18
likes
0
points
52
downloads

Publisher

unverified uploader

Weekly Downloads

A simple to use LAN communication package. The Server and a Client can freely distribute data over LAN.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

dio, emodebug, isohttpd, meta, wifi

More

Packages that depend on client_server_lan