riptide 0.0.1 riptide: ^0.0.1 copied to clipboard
Dart port of the Riptide library from Tom Weiland.
Riptide Dart Port #
Dart port of Riptide, a light weight networking library from Tom Weiland.
This port provides functionality for establishing connections with clients and servers using the Riptide protocol.
Compatibility #
This port was last tested for functionality with Riptide Commit a292470, Feb 12 2023
It was tested for Android and Windows devices.
Compatible libraries in other languages #
Getting started #
The API is mostly identical to Riptide.
Installation #
In you projects pubspec.yaml under dependencies add:
riptide:
git:
url: https://github.com/JayKay135/Riptide-Dart-Port.git
ref: master
Usage #
Enable Logging #
RiptideLogger.initialize(print, true);
Create a new Server #
Server server = Server();
server.start(PORT, 10);
// timer to periodically update the server
Timer.periodic(const Duration(milliseconds: 20), (timer) {
server.update();
});
Handling received message:
server.registerMessageHandler(MESSAGE_ID, handleMessage);
void handleMessage(int clientID, Message message) {
// do something
}
Create a new Client #
Client client = Client();
client.connect(InternetAddress("127.0.0.1"), PORT);
// timer to periodically update the client
Timer.periodic(const Duration(milliseconds: 20), (timer) {
client.update();
});
Handling received message:
client.registerMessageHandler(MESSAGE_ID, handleMessage);
void handleMessage(Message message) {
// do something
}
Send Messages #
Message message = Message.createFromInt(MessageSendMode.reliable, MESSAGE_ID);
message.addString("Hello World !");
client.send(message);
server.sendToAll(message);
Multi threaded Server/ Client #
It is recommended to run the whole server/ client code execution in a seperate isolate to increase performance. A lightweight implementation of such an isolate is provided by this library.
Simply swap from
Server server = Server();
server.start(PORT, 10);
Timer.periodic(const Duration(milliseconds: 20), (timer) {
server.update();
});
to
MultiThreadedServer mtServer = MultiThreadedServer();
mtServer.start(PORT, 10, loggingEnabled: true);
or
Client client = Client();
client.connect(InternetAddress("127.0.0.1"), PORT);
Timer.periodic(const Duration(milliseconds: 20), (timer) {
client.update();
});
to
MultiThreadedClient mtClient = MultiThreadedClient();
mtClient.connect(InternetAddress("127.0.0.1"), PORT, loggingEnabled: true);
Note #
If you are using android: Make sure to enable the internet permission in the AndroidManifest.xml.
Under android/app/src/main/AndroidManifest.xml add
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
...
<uses-permission android:name="android.permission.INTERNET"/>
...
And if you are using an android emulator with localhost note that instead of localhost you should use the ip 10.0.2.2.
Low-Level Transports supported by this library #
- UDP (built-in)
Contributions #
Contributions are very welcome. Especially if you know about low-level udp/ tcp sockets and isolates.
License #
Distributed under the MIT license. See LICENSE.md for more information. Copyright © 2023 VISUS, University of Stuttgart
This project is supported by VISUS, University of Stuttgart