client_server_lan 1.0.2 copy "client_server_lan: ^1.0.2" to clipboard
client_server_lan: ^1.0.2 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 #

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);
  }
18
likes
0
pub points
0%
popularity

Publisher

unverified uploader

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, uuid

More

Packages that depend on client_server_lan