Skip to content

vacp2p/nim-quic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

QUIC for Nim

An implementation of the QUIC protocol in Nim.

Building and testing

Install dependencies:

nimble install -d

Run tests:

nimble test

Examples

Import quic and the chronos async library:

import quic
import chronos

Create server:

let tlsConfig = TLSConfig.init(cert, certPrivateKey, @["alpn"], Opt.none(CertificateVerifier))
let server = QuicServer.init(tlsConfig)

Accept incoming connections:

let address = initTAddress("127.0.0.1:12345")
let listener = server.listen(address)
defer:
  await listener.stop()
  listener.destroy()

while true:
  let connection =
    try:
      await listener.accept()
    except CatchableError:
      return # server stopped
  let stream = await connection.incomingStream()
  
  # read or write data to stream
  let data = await stream.read()

  await stream.close()
  await connection.waitClosed()

Create client:

let tlsConfig = TLSConfig.init(cert, certPrivateKey, @["alpn"], Opt.none(CertificateVerifier))
let client = QuicClient.init(tlsConfig)

Dial server and send message:

let address = initTAddress("127.0.0.1:12345")
let connection = await client.dial(address)
defer:
  await connection.close()

let stream = await connection.openStream()
let message = cast[seq[byte]]("hello form nim quic client")
await stream.write(message)
await stream.close()

Thanks

We would like to thank the authors of the NGTCP2 library, on whose work we're building.

About

QUIC for Nim

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 8

Languages