gen_server

Last updated:

0 purchases

gen_server Image
gen_server Images
Add to Cart

Description:

gen server

GenServer #
Features #

End-to-end encryption
Channel
Reconnect

Class #

GenServer
GenClient
GenSocket

Data Flow #
Usage #
Server
import 'package:gen_server/gen_server.dart';
import 'package:gen_server/gen_socket.dart';

/* Usage & main function here */
Future<GenServer> launchServer() async {
var gen_server = GenServer(host: '0.0.0.0', port: 8080);
gen_server.onConnect((GenSocket gen_socket) {
gen_socket.sendMessage('This is a new message');
gen_socket.sendMessage('This is a new message - 1');
gen_socket.sendMessage('This is a new message - 2');
});
gen_server.onMessage((GenSocket gen_socket, String data) async {
gen_server.log('Message: $data');
await gen_socket.sendMessage('From server::::$data');
});
gen_server.onClose((GenSocket gen_socket) {
print("Socket closed.");
});
gen_server.start();
return gen_server;
}
copied to clipboard
Client
import 'package:gen_server/gen_client.dart';
import 'package:gen_server/gen_socket.dart';

/* Usage & main function here */
Future<GenClient> launchClient() async {
// connect to the socket server
var client = GenClient(host: '127.0.0.1', port: 8080);
client.onConnect(( GenSocket gen_socket) async {
await gen_socket.sendMessage('Hello');
await Future.delayed(Duration(milliseconds: 10));
await gen_socket.sendMessage('Anyone there?');
await Future.delayed(Duration(milliseconds: 10));
await gen_socket.sendMessage('Hi');
await Future.delayed(Duration(milliseconds: 10));
await gen_socket.sendMessage('Oh...');
await Future.delayed(Duration(milliseconds: 10));
await gen_socket.sendMessage('bye..');
// await gen_socket.disconnect();
});
client.onMessage((GenSocket gen_socket, String data) async {
client.log('Message: $data');
});
client.onClose((GenSocket gen_socket) async {
print("Socket closed.");
await Future.delayed(Duration(milliseconds: 100));
await gen_socket.reconnect();
});
await client.start();
return client;
}

void main() async {

var client = await launchClient();

}

copied to clipboard
Links #
Author/Contributors #

Samick - created at 2022.05.17

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.