client_server_lan 1.1.0
client_server_lan: ^1.1.0

Dart native
Flutter Android iOS

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.

Usage #

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<dynamic>.delayed(const Duration(seconds: 2));
    clientIPs = "";
    for (final s in server.clientsConnected) {
      setState(() {
        clientIPs += "id=${s.name},IP=${s.address}\n";
      });
    }
  }

Transfer Data #

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);
  }
4
likes
100
pub points
53%
popularity

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

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

robert.aries1@gmail.com

License

MIT (LICENSE)

Dependencies

dio, emodebug, isohttpd, meta

More

Packages that depend on client_server_lan