package websocket-async

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Module Websocket_async: websocket library for Async

This module implements a websocket client and server library in the spirit of the otherwise similar TCP functions of the Lwt_io module. The websocket protocol add message framing in addition of simple TCP communication, and this library implement framing and unframing of messages.

module Frame = Websocket.Frame
val client : ?log:Async.Log.t -> ?name:string -> ?extra_headers:Cohttp.Header.t -> ?random_string:(int -> string) -> ?initialized:unit Async.Ivar.t -> app_to_ws:Frame.t Async.Pipe.Reader.t -> ws_to_app:Frame.t Async.Pipe.Writer.t -> net_to_ws:Async.Reader.t -> ws_to_net:Async.Writer.t -> Uri.t -> unit Async.Deferred.Or_error.t
val client_ez : ?opcode:Frame.Opcode.t -> ?log:Async.Log.t -> ?name:string -> ?extra_headers:Cohttp.Header.t -> ?heartbeat:Core.Time_ns.Span.t -> ?random_string:(int -> string) -> Uri.t -> Async.Reader.t -> Async.Writer.t -> string Async.Pipe.Reader.t * string Async.Pipe.Writer.t
val server : ?log:Async.Log.t -> ?name:string -> ?check_request:(Cohttp.Request.t -> bool Async.Deferred.t) -> ?select_protocol:(string -> string option) -> reader:Async.Reader.t -> writer:Async.Writer.t -> app_to_ws:Frame.t Async.Pipe.Reader.t -> ws_to_app:Frame.t Async.Pipe.Writer.t -> unit -> unit Async.Deferred.Or_error.t

server ?log ?request_cb reader writer app_to_ws ws_to_app () returns a thread that expects a websocket client connected to reader/writer and, after performing the handshake, will resp. read outgoing frames from app_to_ws and write incoming frames to ws_to_app. The thread is determined if any of reader, writer, app_to_ws, ws_to_app is closed. If case of an error, app_to_ws and ws_to_app will be closed. Upon reception of the client HTTP request, request_cb will be called with the request as its argument. If request_cb returns true, the connection will proceed, otherwise, the result is immediately determined to Error Exit.

OCaml

Innovation. Community. Security.