|
| 1 | +# Aether |
| 2 | +Aether is a lightweight socket transport framework. It provides a basic abstraction layer for serialization of objects and transport over sockets. |
| 3 | + |
| 4 | +## Eon |
| 5 | +Eon is the serialization format used by Aether. It is a binary format designed for efficiency and ease of use. |
| 6 | +### Utility Classes |
| 7 | +The Eon Reader and Writer classes provide methods for reading and writing Eon-encoded data. They support various data types. |
| 8 | +### Kotlinx Serialization |
| 9 | +Aether integrates with Kotlinx Serialization to allow easy serialization and deserialization of Kotlin data classes to and from Eon format. |
| 10 | +Therefore, classes intended for serialization must be annotated with `@Serializable`. |
| 11 | + |
| 12 | +## Socket Transport |
| 13 | +Aether provides a socket transport layer that allows for sending and receiving Eon-encoded data over TCP sockets. |
| 14 | +### Bridge |
| 15 | +Aether includes a bridge component that facilitates communication between different systems or components using the socket transport layer. |
| 16 | +The bridge provides useful methods for interacting with the socket, such as sending and receiving packets, yet still allows low-level access to the underlying socket if needed. |
| 17 | +### Timestamps |
| 18 | +Aether automatically timestamps packets sent over the socket transport, allowing for tracking of message timing. |
| 19 | +### ObjectIds |
| 20 | +Sent packets can be tagged with objectIds to easily identify the source-type of the data being transmitted. |
| 21 | +For example, a packet containing user data might be tagged with an objectId of 1. When a packet is received, the objectId can be used to determine that the data is of type user data. |
| 22 | +This is of course fully optional. |
| 23 | + |
| 24 | +## Hooks |
| 25 | +Aether provides all its event logic in one place. When initializing either a server or a client, you can provide hooks for various events such as connection established, data received etc. |
| 26 | + |
| 27 | +```kotlin |
| 28 | +AetherServer.suspended.start(9999) { |
| 29 | + onClientConnected += { bridge -> |
| 30 | + println("Client connected: ${bridge.socket.inetAddress.hostAddress}") |
| 31 | + } |
| 32 | + |
| 33 | + onClose += { |
| 34 | + println("Server is closing.") |
| 35 | + } |
| 36 | +} |
| 37 | +``` |
| 38 | + |
| 39 | +## Async I/O |
| 40 | +Aether leverages Kotlin Coroutines for asynchronous I/O operations, making it easy to work with non-blocking socket communication. |
| 41 | +### Packet listeners |
| 42 | +Both client and server have the capability to asynchronously listen for packets. |
| 43 | + |
| 44 | +```kotlin |
| 45 | +onPacketReceived += { bridge -> |
| 46 | + val (objectId, buffer) = bridge.readPacketBuffer() |
| 47 | + |
| 48 | + println("Packet received with object ID: $objectId") |
| 49 | + |
| 50 | + when (objectId) { |
| 51 | + 1 -> { |
| 52 | + val packet = bridge.decodeWithPayloadType<MyObject>(buffer) |
| 53 | + val obj = packet.payload |
| 54 | + val timestamp = packet.timestamp |
| 55 | + println("Received message: ${obj.message} at $timestamp") |
| 56 | + |
| 57 | + this.broadcast(obj, 1) |
| 58 | + } |
| 59 | + } |
| 60 | +} |
| 61 | +``` |
0 commit comments