riptide

Last updated:

0 purchases

riptide Image
riptide Images
Add to Cart

Description:

riptide

Riptide Dart Port #



Dart port of Riptide, a lightweight 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 945e4a0, Jan 29 2024

NOTE: Riptide itself is not backward compatible. This library will currently only work with Riptide version v2.1.2 or v2.2.0.
The older version (pub 0.0.3) will still work with Riptide v2.0.0, but with limited features (e.g. missing tcp support).
For more details about which pub versions correspond to what Riptide version take a look at the changelog.
Important Notes #
The dart language differs C# in some key aspects.

There is no function overloading in dart. Therefore, you have to deal with many different function names in the message class.
If you find a cleaner solution, do not hesitate to open up a pull request.
There is no ulong type in dart. C#'s longs are signed 64bit values. So are the int values in dart. Longs can be represented without any issues in dart using ints. Unfortunately, there is no unsigned 64-bit type in dart. The representation of ulongs in dart is, therefore, not easily possible. Currently, ulongs will get parsed to ints. Please note that this might result in data loss.

Compatible libraries in other languages #

C#: Riptide
Python: Pytide

Getting started #
The API is mostly identical to Riptide.
Usage #
Enable Logging #
RiptideLogger.initialize(print, true);
copied to clipboard
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();
});
copied to clipboard
Handling received message:
server.registerMessageHandler(MESSAGE_ID, handleMessage);

void handleMessage(int clientID, Message message) {
// do something
}
copied to clipboard
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();
});
copied to clipboard
Handling received message:
client.registerMessageHandler(MESSAGE_ID, handleMessage);

void handleMessage(Message message) {
// do something
}
copied to clipboard
Send Messages #
Message message = Message.createFromInt(MessageSendMode.reliable, MESSAGE_ID);
message.addString("Hello World !");

client.send(message);
server.sendToAll(message);
copied to clipboard
Multi threaded Server/ Client #
It is recommended to run the whole server/ client code execution in a separate isolate to increase performance.
This library provides a lightweight implementation of such an isolate.
Simply swap from
Server server = Server();
server.start(PORT, 10);

Timer.periodic(const Duration(milliseconds: 20), (timer) {
server.update();
});
copied to clipboard
to
MultiThreadedServer mtServer = MultiThreadedServer();
mtServer.start(PORT, 10, loggingEnabled: true);
copied to clipboard
or
Client client = Client();
client.connect(InternetAddress("127.0.0.1"), PORT);

Timer.periodic(const Duration(milliseconds: 20), (timer) {
client.update();
});
copied to clipboard
to
MultiThreadedClient mtClient = MultiThreadedClient();
mtClient.connect(InternetAddress("127.0.0.1"), PORT, loggingEnabled: true);
copied to clipboard

If you want to use a different transport with the multi-threaded variants, pass it as an argument in the constructor call.
e.g.
MultiThreadedClient mtClient = MultiThreadedClient(transportType: MultiThreadedTransportType.tcp);
mtClient.connect(InternetAddress("127.0.0.1"), PORT, loggingEnabled: true);
copied to clipboard
Additional 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"/>
...
copied to clipboard
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 Transport (built-in)
TCP Transport (built-in)

Contributions #
Contributions are 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 © 2024 VISUS, University of Stuttgart
This project is supported by VISUS, University of Stuttgart

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.