pony-websocket
WebSocket server for pony
It's RFC6455 conformant, see test report.
Installation
- Install pony-stable
stable add github oraoto/pony-websocketstable fetchto fetch your dependenciesuse "websocket"to include this packagestable env ponycto 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.