Skip to content

Commit

Permalink
doc: update readme
Browse files Browse the repository at this point in the history
Signed-off-by: iGxnon <igxnon@gmail.com>
  • Loading branch information
iGxnon committed Jul 31, 2024
1 parent 119e3be commit 9273226
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ See [examples](examples/) for basic usage.

### Server

[IO](src/io.rs) is a hidden type that implements the traits `Stream` and `Sink`.
Most operations are performed on `Stream` and `Sink`.

Keep polling `incoming` because it also serves as the router to every IOs.
Keep polling `incoming` because it also serves as the router to every connections.
Apply `Sink::poll_flush` to IO will trigger to flush all pending packets, `ACK`/`NACK`, and stale packets.
Apply `Sink::poll_close` to IO will ensure that all data is received by the peer before returning (i.e It may keep resending infinitely.).

Expand All @@ -56,9 +56,9 @@ let config = server::Config::new()
.advertisement(&b"Hello, I am server"[..])
...
let mut incoming = socket.make_incoming(config);
let mut io = incoming.next().await.unwrap();
let data: Bytes = io.next().await.unwrap();
io.send(data).await.unwrap();
let (reader, _) = incoming.next().await.unwrap();
tokio::pin!(reader);
let data: Bytes = reader.next().await.unwrap();
```

### Client
Expand All @@ -69,14 +69,15 @@ io.send(data).await.unwrap();
use bytes::Bytes;
use futures::{SinkExt, StreamExt};
use raknet_rs::client::{self, ConnectTo};
use raknet_rs::Reliability;

let socket = tokio::net::UdpSocket::bind("0.0.0.0:0").await?;
let config = client::Config::new()
.send_buf_cap(1024)
.client_guid(1919810)
...
let mut conn = socket.connect_to(<addr>, config).await?;
conn.send(Bytes::from_static(b"Hello, Anyone there?"))
let (_, writer) = socket.connect_to(<addr>, config).await?;
tokio::pin!(writer);
writer.send(Message::new(Reliability::Reliable, 0, Bytes::from_static(b"Hello, Anyone there?")))
.await?;
let res: Bytes = conn.next().await.unwrap();
```

0 comments on commit 9273226

Please sign in to comment.