Skip to content
WebSocket server for Ponylang🐴
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.
.circleci
examples
reports
tests
websocket
.gitignore
LICENSE
Makefile
README.md

README.md

pony-websocket

CircleCI stability

WebSocket server for pony

It's RFC6455 conformant, see test report.

Installation

  • Install pony-stable
  • stable add github oraoto/pony-websocket
  • stable fetch to fetch your dependencies
  • use "websocket" to include this package
  • stable env ponyc to compile your application

Usage

The API is model after the net package and much simplified.

Here is a simple echo server:

use "websocket"

actor Main
  new create(env: Env) =>
    try
      let listener = WebSocketListener(
        env.root as AmbientAuth, EchoListenNotify, "127.0.0.1","8989")
    end

class EchoListenNotify is WebSocketListenNotify
  // A tcp connection connected, return a WebsocketConnectionNotify instance
  fun ref connected(): EchoConnectionNotify iso^ =>
    EchoConnectionNotify

class EchoConnectionNotify is WebSocketConnectionNotify
  // A websocket connection enters the OPEN state
  fun ref opened(conn: WebSocketConnection ref) =>
    @printf[I32]("New client connected\n".cstring())

  // UTF-8 text data received
  fun ref text_received(conn: WebSocketConnection ref, text: String) =>
    // Send the text back
    conn.send_text(text)

  // Binary data received
  fun ref binary_received(conn: WebSocketConnection ref, data: Array[U8] val) =>
    conn.send_binary(data)

  // A websocket connection enters the CLOSED state
  fun ref closed(conn: WebSocketConnection ref) =>
    @printf[I32]("Connection closed\n".cstring())

An simplified API is also provided: example.

See more examples.

You can’t perform that action at this time.