add sctp examples

This commit is contained in:
Ludovic Chenut 2023-08-18 17:14:03 +02:00
parent c28ae5ca31
commit 8e826f7eb2
No known key found for this signature in database
GPG Key ID: D9A59B1907F1D50C
2 changed files with 27 additions and 0 deletions

14
examples/sctp_client.nim Normal file
View File

@ -0,0 +1,14 @@
import chronos, stew/byteutils
import ../webrtc/sctp
proc main() {.async.} =
let
sctp = Sctp.new(port = 4244)
address = TransportAddress(initTAddress("127.0.0.1:4242"))
conn = await sctp.connect(address, sctpPort = 13)
await conn.write("test".toBytes)
let msg = await conn.read()
echo "Client read() finished ; receive: ", string.fromBytes(msg)
await conn.close()
waitFor(main())

13
examples/sctp_server.nim Normal file
View File

@ -0,0 +1,13 @@
import chronos, stew/byteutils
import ../webrtc/sctp
proc main() {.async.} =
let sctp = Sctp.new(port = 4242)
sctp.startServer(13)
let conn = await sctp.listen()
let msg = await conn.read()
echo "Receive: ", string.fromBytes(msg)
await conn.close()
sctp.stopServer()
waitFor(main())