From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 5DECC7EEF6 for ; Tue, 16 Jun 2015 17:41:58 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of dhouse@janestreet.com) identity=pra; client-ip=38.105.200.112; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="dhouse@janestreet.com"; x-sender="dhouse@janestreet.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of dhouse@janestreet.com designates 38.105.200.112 as permitted sender) identity=mailfrom; client-ip=38.105.200.112; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="dhouse@janestreet.com"; x-sender="dhouse@janestreet.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mxout1.mail.janestreet.com) identity=helo; client-ip=38.105.200.112; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="dhouse@janestreet.com"; x-sender="postmaster@mxout1.mail.janestreet.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0DXAQC2QoBVnHDIaSZbgkWBfgaDGMJkAoE6B0wBAQEBAQESAQEBAQEGFglPhCIBAQEDARIRBBkBATcBBAsJAgsNIAoCAiEBEgEFARwGEyKHeAMKCAOZSZBrPjGKT3CEZAEFjEENhTkBAQEBAQEBAwEBAQEBAQEBFAYKizqCTYFuSweCaIFFk2SJZIFhgTOHEYg+gzuCERIjgRWEIG6BAySBIAEBAQ X-IPAS-Result: A0DXAQC2QoBVnHDIaSZbgkWBfgaDGMJkAoE6B0wBAQEBAQESAQEBAQEGFglPhCIBAQEDARIRBBkBATcBBAsJAgsNIAoCAiEBEgEFARwGEyKHeAMKCAOZSZBrPjGKT3CEZAEFjEENhTkBAQEBAQEBAwEBAQEBAQEBFAYKizqCTYFuSweCaIFFk2SJZIFhgTOHEYg+gzuCERIjgRWEIG6BAySBIAEBAQ X-IronPort-AV: E=Sophos;i="5.13,627,1427752800"; d="scan'208";a="136512404" Received: from mxout1.mail.janestreet.com ([38.105.200.112]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES128-SHA; 16 Jun 2015 17:41:57 +0200 Received: from tot-qpr-mailcore1.delacy.com ([172.27.56.68] helo=tot-qpr-mailcore1) by mxout1.mail.janestreet.com with smtp (Exim 4.82) (envelope-from ) id 1Z4szr-0001Kk-K0 for caml-list@inria.fr; Tue, 16 Jun 2015 11:41:55 -0400 X-JS-Flow: external Received: by tot-qpr-mailcore1 with JS-mailcore (0.1) (envelope-from ) id BVgEPD-AAAHCK-S8; 2015-06-16 11:41:55.607077-04:00 Received: from mail-qc0-f181.google.com ([209.85.216.181]) by mxgoog1.mail.janestreet.com with esmtps (UNKNOWN:AES128-GCM-SHA256:128) (Exim 4.72) (envelope-from ) id 1Z4szr-0006At-GS for caml-list@inria.fr; Tue, 16 Jun 2015 11:41:55 -0400 Received: by qcsf5 with SMTP id f5so5427697qcs.2 for ; Tue, 16 Jun 2015 08:41:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=google; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=8ej1n4Wq9xxsAYzeli+5VZ+f7eMjDEYnmTuVKihK5YA=; b=Jo/Y2k4HKDAl4L+YOIpHJfGBSr4sXHEzdaCiW5CtEK0RyYaCVntx8d0dr3csIi2QLG Ua1A3kf1bNBUDBN9XMNdG90en8QbluQG2uuG4Rj5hQUHzMGZ211h10aTygXspqsbwsYL BPxi6FeMLTZLcV+p4uPkANJb1VOc54U+JXH5c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=8ej1n4Wq9xxsAYzeli+5VZ+f7eMjDEYnmTuVKihK5YA=; b=XY2jhZD0A6a6LGS+Jz5qh69m1MTuPsB5D07ILuuIibV1F2ISxgqEtZCZZEU4ijqwI9 /f3oNDuaoszXp2qYwwdNYuFTndQDC1+zA3TUttjgtLogFMf4pPEeFCr789yR9sX4Hwuf +VODAD1j0vX4SxPocm6NwRIURyhouiED71QWqqY5K3bmSt16aOIUg5844xNHx4ao6xbf v33nPLWqmi5U7Zn0qyLZC5q3ZDxjZiaYUKCmBEaAoTMUpEQkkl1umC1b+tLFnPWv/JcA 0Rp66a5KdvwcSeo7BQG7Zjf0sQYe/IxMQslzDo6vNI/xqs7IcuLWkvyRcM2mmhz1lnR7 kEzw== X-Gm-Message-State: ALoCoQmLDmMQq8hKABZ142f3B540pHsrNAIg9mF3SEy8CH82hbZWHFYpT0DWhkeGxjDGIiUFzozFtWVo2NwwwGUE5VsVDZbRN4lya5xmzHuNhOWCcJNueGj7PTY/oAc70fA9Tnd1gTc5 X-Received: by 10.55.42.1 with SMTP id q1mr2515405qkh.3.1434469315253; Tue, 16 Jun 2015 08:41:55 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.55.42.1 with SMTP id q1mr2515382qkh.3.1434469315138; Tue, 16 Jun 2015 08:41:55 -0700 (PDT) Received: by 10.140.107.102 with HTTP; Tue, 16 Jun 2015 08:41:55 -0700 (PDT) In-Reply-To: References: Date: Tue, 16 Jun 2015 16:41:55 +0100 Message-ID: From:David House To:Kenneth Adam Miller Cc:caml users Content-Type: multipart/alternative; boundary=001a11473db0f88bc10518a4694a X-JS-Processed-by: mailcore Subject: Re: [Caml-list] Async Server not executing --001a11473db0f88bc10518a4694a Content-Type: text/plain; charset=UTF-8 Ah, now I read your code in more detail I think I see why. Reader.contents on the server side will block until eof. The client side sends some stuff, but does not close the writer, so the server never sees eof. (Recall that sockets are not like files: it's possible to read all of the available data right now, but not reach eof.) Network protocols normally have some explicit "this is the end of one message" marker, like a newline or something similar. Then the server just reads chunks until it sees that marker, at which point it can put the message together and to something with it. For example, you could use Writer.write_line on the client side and Reader.read_line on the server side. On 16 June 2015 at 16:36, Kenneth Adam Miller wrote: > So, now I can get server received if I add that into the callback, but at > "writing shutdown to server" I don't see response received or even > something for Eof. > > On Tue, Jun 16, 2015 at 11:09 AM, David House > wrote: > >> The first thing to try is to make sure that everything is getting >> flushed. For temporary debugging messages I strongly recommend just using >> [Core.Std.eprintf "\n%!"]. >> >> On 16 June 2015 at 16:03, Kenneth Adam Miller < >> kennethadammiller@gmail.com> wrote: >> >>> I'm having trouble with OCaml Async. I wrote a small server with it, and >>> right now I'm trying to unit test that server. Here's my code for the >>> server: >>> >>> >>> let _main ()= >>> print_endline "Server running"; >>> let handler = print_endline in >>> let socket = Tcp.on_port 5554 in >>> let server = Tcp.Server.create socket (fun addr r w -> >>> (Reader.contents r) >>| handler; (Writer.write w "got it")) in >>> server >>> >>> >>> >>> In my unit test code I have: >>> >>> let test_shutdown test_ctxt = Thread_safe.block_on_async_exn (fun () -> >>> ( >>> print_endline "test_shutdown"; >>> let server = Server._main () in >>> server >>= fun server -> >>> let where = Tcp.to_host_and_port "127.0.0.1" 5554 in >>> Tcp.connect where >>= fun s -> >>> let socket, r, w = s in >>> ignore (Writer.write w "kill"); >>> ignore (Writer.flushed w); >>> (Reader.recv r >>> function >>> | `Ok result -> print_endline ("writing shutdown to server" >>> ^ result) >>> | `Eof -> ()); >>> return () >>> )); () >>> >>> >>> >>> I see test_shutdown and Server running, but not sign of "writing >>> shutdown to server" or even "got it"; why isn't my server or even any of >>> the connection executing? >>> >> >> > --001a11473db0f88bc10518a4694a Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Ah, now I read your code in more detail I think I see why.=

Reader.contents on the server side will block until eof= . The client side sends some stuff, but does not close the writer, so the s= erver never sees eof. (Recall that sockets are not like files: it's pos= sible to read all of the available data right now, but not reach eof.)

Network protocols normally have some explicit "th= is is the end of one message" marker, like a newline or something simi= lar. Then the server just reads chunks until it sees that marker, at which = point it can put the message together and to something with it.
<= br>
For example, you could use Writer.write_line on the client si= de and Reader.read_line on the server side.

On 16 June 2015 at 16:36, Kenneth Ada= m Miller <kennethadammiller@gmail.com> wrote:
<= blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px= #ccc solid;padding-left:1ex">
So, now I can get server rec= eived if I add that into the callback, but at "writing shutdown to ser= ver" I don't see response received or even something for Eof.

On Tue, Jun 16, 2015 at 11:09 AM, David House <dhouse@janestreet.com> wrote:
The first thing to try is to make sure that everything= is getting flushed. For temporary debugging messages I strongly recommend = just using [Core.Std.eprintf "<message>\n%!"].

On 16 June 201= 5 at 16:03, Kenneth Adam Miller <kennethadammiller@gmail.com= > wrote:
I'm ha= ving trouble with OCaml Async. I wrote a small server with it, and right no= w I'm trying to unit test that server. Here's my code for the serve= r:


let _= main=C2=A0()=3D
=C2=A0= print_endline=C2=A0
"Server running";
=C2=A0 let handler=C2=A0=
=3D=C2=A0print_endline=C2= =A0in
=C2=A0 let socket= =C2=A0
=3D=C2=A0Tcp
.on_p= ort=C2=A05554=C2=A0in
=C2=A0 let server=C2=A0=3D=C2=A0Tcp.Server.create socket=C2=A0= (fun addr r w=C2=A0->
=C2=A0 =C2=A0 =C2=A0=C2=A0(Reader.contents r)=C2=A0>>|=C2=A0handler;= =C2=A0(Writer<= span style=3D"margin:0px;padding:0px;border:0px;vertical-align:baseline;col= or:rgb(102,102,0)">.write w=C2=A0"got it"))in
=C2=A0 server=



In my uni= t test code I have:
let test_shutdown test_ctxt=C2=A0=3D= =C2=A0Thread_safe.block_on_async_exn=C2=A0(fun=C2=A0()<= /span>=C2=A0->=C2=A0(
=C2=A0= =C2=A0 =C2=A0 print_endline=C2=A0
"test_shutd= own";
=C2=A0 =C2= =A0 =C2=A0 let server=C2=A0
=3D=C2=A0Server._main=C2=A0()=C2=A0in
=C2=A0 = =C2=A0 =C2=A0 server=C2=A0
>>=3D=C2=A0fun server=C2=A0
->
=C2=A0 =C2=A0 =C2=A0 let=C2=A0
wh= ere=C2=A0=3D=C2=A0Tcp.<= /span>to_host_and_port=C2=A0"= 127.0.0.1"=C2=A05554= =C2=A0in
=C2=A0 =C2=A0 =C2=A0=C2=A0
Tcp.
connect=C2=A0where=C2=A0>>= =3D=C2=A0fun s=C2=A0->= =C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0 let socket,=C2=A0r,=C2=A0w=C2=A0=3D=C2=A0s=C2=A0in
=C2=A0 =C2=A0 =C2=A0 =C2=A0 ignore=C2=A0
(Writer.<= span style=3D"margin:0px;padding:0px;border:0px;vertical-align:baseline;col= or:rgb(0,0,0)">write w=C2=A0
"kill");
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 ignore=C2=A0
(Writ= er.flushed w);
=C2=A0 =C2=A0 =C2=A0 =C2=A0=C2= =A0
(Reader.
recv r=C2=A0>>>=C2=A0funct= ion
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0|=C2=A0Eof=C2=A0->=C2=A0());
=C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0
return<= /span>=C2=A0()
=C2=A0 =C2=A0=C2=A0
));=C2=A0()

=


I see test_shutdown and Server running, but= not sign of "writing shutdown to server" or even "got it&qu= ot;; why isn't my server or even any of the connection executing?
=



--001a11473db0f88bc10518a4694a--