tcp_socket_connection 0.0.9 copy "tcp_socket_connection: ^0.0.9" to clipboard
tcp_socket_connection: ^0.0.9 copied to clipboard

outdated

A flutter package to connect, listen to and send messages over tcp sockets.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:tcp_socket_connection/tcp_socket_connection.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  //Instantiating the class with the Ip and the PortNumber
  TcpSocketConnection socketConnection=TcpSocketConnection("192.168.1.113", 10251);
  String message="";

  @override
  void initState() {
    super.initState();
    startConnection();
  }

  //receiving and sending back a custom message
  void messageReceived(String msg){
    setState(() {
      message=msg;
    });
    socketConnection.sendMessage("MessageIsReceived :D");
  }

  //starting the connection and listening to the socket asynchronously
  void startConnection() async{
    await socketConnection.connect(5000, "EOS", messageReceived);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Text(
          'You have received '+ message,
        ),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
42
likes
0
pub points
88%
popularity

Publisher

unverified uploader

A flutter package to connect, listen to and send messages over tcp sockets.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on tcp_socket_connection