add example sctp_both.nim

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

27
examples/sctp_both.nim Normal file
View File

@ -0,0 +1,27 @@
import chronos, stew/byteutils
import ../webrtc/sctp as sc
let sctp = Sctp.new(port = 4242)
proc serv(fut: Future[void]) {.async.} =
#let sctp = Sctp.new(port = 4242)
sctp.startServer(13)
fut.complete()
let conn = await sctp.listen()
echo "await read()"
let msg = await conn.read()
echo "read() finished"
echo "Receive: ", string.fromBytes(msg)
await conn.close()
sctp.stopServer()
proc main() {.async.} =
let fut = Future[void]()
asyncSpawn serv(fut)
await fut
#let sctp = Sctp.new(port = 4244)
let address = TransportAddress(initTAddress("127.0.0.1:4242"))
let conn = await sctp.connect(address, sctpPort = 13)
await conn.write("test".toBytes)
await conn.close()
waitFor(main())