client_server_sockets 0.0.1 client_server_sockets: ^0.0.1 copied to clipboard
A simple client-server sockets package that uses the Socket and ServerSocket classes.
A simple client-server sockets package that uses the Socket and ServerSocket classes.
Getting started #
Add the dependency:
dependencies:
sockets: ^0.0.1
Import the package:
import 'package:sockets/sockets.dart';
Usage #
Start the server on an address you want:
Server server = Server();
await server.startServer("192.168.1.2");
Add the callback function to prevent it from throwing a null exception:
server.onSocketDone = (port) {
// Logic for when socket is closed
};
Listen to the response stream:
server.stream.listen(print);
Now initialize the client and connect to the server:
Client client = Client();
await client.connect("192.168.1.2");
Add the callback function to prevent it from throwing a null exception:
client.onSocketDone = () {
// Logic for when socket is closed
};
Listen to the response stream:
client.stream.listen(print);
To send a message to the server, use the send()
function like this:
client.send("Hello World!");