Skip to content
news - nIm easy web socket. Based on https://github.com/treeform/ws
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests fix news Jun 12, 2019
.gitignore
LICENSE
README.md
news.nimble

README.md

NEWS - Nim Easy WebSocket.

Example Echo Server:

Example echo server, will repeat what you send it:

import news, asyncdispatch, asynchttpserver

var server = newAsyncHttpServer()
proc cb(req: Request) {.async.} =
  if req.url.path == "/ws":
    var ws = await newWebsocket(req)
    await ws.send("Welcome to simple echo server")
    while ws.readyState == Open:
      let packet = await ws.receivePacket()
      await ws.send(packet)
  await req.respond(Http200, "Hello World")

waitFor server.serve(Port(9001), cb)

Websocket client

Send messages to Echo server and receive unswer

import news, asyncdispatch

proc sendMsg() {.async.} =
    var ws = await newWebSocket("ws://localhost:9001/ws")
    await ws.send("hi")
    while ws.readyState == Open:
        let packet = await ws.receivePacket()
        echo "received ", packet

waitFor sendMsg()

Websocket with chronos support:

import chronos

const newsUseChronos = true
include news

proc sendMsg() {.async.} =
    var ws = await newWebSocket("ws://localhost:9001/ws")
    await ws.send("hi")
    while ws.readyState == Open:
        let packet = await ws.receivePacket()
        echo "received ", packet

waitFor sendMsg()
You can’t perform that action at this time.