Content-Type: multipart/alternative; boundary=001a11354680d9d1ce05420f3605
Subject: [Caml-list] Compressing stream in Async.Tcp.Server
--001a11354680d9d1ce05420f3605
Content-Type: text/plain; charset=UTF-8
Hi all, I'm writing a simple client/server application using Async.Rpc. The
skeletons of the client and server is essentially derived from the examples
available on line.
Since the messages are highly compressible, I would like to use ZLib (e.g.
Cryptokit) but I can't figure out how.
Any ideas?
CLIENT:
* Tcp.with_connection*
* (Tcp.to_host_and_port host port)*
* ~timeout:(sec 1.)*
* (fun _ r w ->*
* (* COMPRESSION HERE, HOW? *)*
* Rpc.Connection.create r w ~connection_state:Pervasives.ignore*
* >>= function*
* | Error exn -> raise exn*
* | Ok conn -> begin*
* let msg = {*
* Rpc_protocol.scada_uuid = conf.Config_manager.scada_uuid;*
* measures;*
* } in*
* Rpc.Rpc.dispatch Rpc_protocol.export_data_rpc conn msg >>=
function*
* | Ok response -> return response*
* | Error e -> begin*
* error ~tags "SERVER SIDE EXCEPTION";*
* error ~tags " %s" (Error.to_string_hum e);*
* return false*
* end*
* end*
* )*
SERVER:
* Tcp.Server.create*
* ~on_handler_error:(`Call (fun _ exn -> Log.Global.sexp (Exn.sexp_of_t
exn)))*
* (Tcp.on_port port)*
* (fun _addr r w ->*
* (* COMPRESSION HERE, HOW? *)*
* Rpc.Connection.server_with_close r w*
* ~connection_state:(fun c ->*
* {*
* db_thread = db_thread;*
* }*
* )*
* ~on_handshake_error:(*
* `Call (fun exn -> Log.Global.sexp (Exn.sexp_of_t exn); return
()))*
* ~implementations)*
--
*Paolo*
--001a11354680d9d1ce05420f3605
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Hi all, I'm writing a simple client/server a=
pplication using Async.Rpc. The skeletons of the client and server is essen=
tially derived from the examples available on line.
Since the messages are highly compressible, I would like to use ZLib=
(e.g. Cryptokit) but I can't figure out how.
=
Any ideas?
CLIENT:
<=
font face=3D"monospace, monospace">=C2=A0 =C2=A0 Tcp.with_connection=
=C2=A0 =C2=A0 =C2=A0 =
(Tcp.to_host_and_port host port)
=C2=A0 =C2=A0 =C2=A0 ~timeout:(sec 1.)
=C2=A0 =C2=A0 =C2=A0 (fun _ r w -=
>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 (*=
COMPRESSION HERE, HOW? *)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 Rpc.Connection.create=
r w ~connection_state:Pervasives.ignore
=C2=A0 =C2=A0 =C2=A0 =C2=A0 >>=3D func=
tion
=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 | Error exn -> raise exn
=C2=A0 =C2=A0 =C2=A0 =C2=A0 | Ok conn =C2=A0=
-> begin
=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 let msg =3D {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
=C2=A0 =C2=A0 Rpc_protocol.scada_uuid =3D conf.Config_manager.scada_u=
uid;=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 measures;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
} in
=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Rpc.Rpc.dispatch Rpc_protocol.export_dat=
a_rpc conn msg >>=3D function
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | Ok respons=
e -> return response
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | Error e -> begin
=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 error ~tags "SERVER SIDE EXCEPT=
ION";
=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 error ~tags " =C2=
=A0 =C2=A0%s" (Error.to_string_hum e);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 return false
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 end=C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 end
=C2=
=A0 =C2=A0 =C2=A0 )
SERVER:=C2=A0 Tcp.=
Server.create
=
=C2=A0 =C2=A0 ~on_handler_error:(`Call (fun _ exn -> Log.Global.sexp (Ex=
n.sexp_of_t exn)))
=C2=A0 =C2=A0 (Tcp.on_port port)
=C2=A0 =C2=A0 (fun _addr r w ->
=C2=A0 =C2=A0 =C2=A0 (* COMPRESSION HERE, HOW? *)
=C2=A0 =
=C2=A0 =C2=A0 Rpc.Connection.server_with_close r w
=C2=A0 =C2=A0 =C2=A0 =C2=A0 ~conne=
ction_state:(fun c ->=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 d=
b_thread =3D db_thread;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }
=C2=A0 =C2=A0 =C2=A0 =C2=A0 )=C2=A0 =C2=A0 =C2=A0 =C2=A0 ~=
on_handshake_error:(
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 `Call (fun exn -> Log.Global.se=
xp (Exn.sexp_of_t exn); return ()))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 ~implementations)=
b>
--
--001a11354680d9d1ce05420f3605--