我不確定如何完全使用OCaml Websocket庫。我希望有人能用一個簡單的例子來幫助我。我正試圖在websocket.org上測試這個庫。我只是想發送一條消息,然後打印迴應。我很困惑如何使用/訪問由ws_conn
返回的功能。我認爲我可以像let push,print = ws_conn in
或let push,print = Websocket.open_connection ~tls:false ws_addr in
這樣做,但這似乎不正確。這是我到目前爲止。OCaml Websocket示例
#require "websocket";;
(* Set up the websocket uri address *)
let ws_addr = Uri.of_string "ws://echo.websocket.org"
(* Set up the websocket connection *)
let ws_conn = Websocket.open_connection ~tls:false ws_addr
(* Set up a frame *)
let ws_frame = Websocket.Frame.of_string "Rock it with HTML5 WebSocket"
(* Function to handle replies *)
let with_reply s =
match s with
| Some x ->
let line = Websocket.Frame.content x in
print_string line
| None ->
print_string "Error Recieved no reply ..."
看起來不錯。很高興我能幫上忙。 :) – nlucaroni 2014-09-22 22:30:03
此API不再工作,Websocket庫不再具有「open_connection」功能。 – 2017-12-28 07:17:50