From d6c2877fc2eb544d74fac392b2a5763610b6d4ab Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Fri, 18 Aug 2023 17:19:06 +0200 Subject: [PATCH] add example sctp_both.nim --- examples/sctp_both.nim | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 examples/sctp_both.nim diff --git a/examples/sctp_both.nim b/examples/sctp_both.nim new file mode 100644 index 0000000..d801f6b --- /dev/null +++ b/examples/sctp_both.nim @@ -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())