diff options
| author | Marcos Magueta <maguetamarcos@gmail.com> | 2024-11-26 04:24:42 -0300 |
|---|---|---|
| committer | Marcos Magueta <maguetamarcos@gmail.com> | 2024-11-26 04:24:42 -0300 |
| commit | 872fc56a414f8c2a4818463be9e104195a0b6242 (patch) | |
| tree | 07d1591e043031fe21211400d53f4dd7c4b47bd7 /lib/server.ml | |
| parent | f487fbee29dcebf62400be20fd509ba1794e952f (diff) | |
| download | Sakura-872fc56a414f8c2a4818463be9e104195a0b6242.tar.gz Sakura-872fc56a414f8c2a4818463be9e104195a0b6242.zip | |
send XML through sockets
Diffstat (limited to 'lib/server.ml')
| -rw-r--r-- | lib/server.ml | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/lib/server.ml b/lib/server.ml index 6544f81..22bee73 100644 --- a/lib/server.ml +++ b/lib/server.ml @@ -17,16 +17,18 @@ let client_read sock maxlen = let rec _read sock acc = Lwt_unix.read sock str 0 maxlen >>= fun recvlen -> Lwt_io.write_line Lwt_io.stdout (Printf.sprintf "[LOG] Received %d bytes from client" recvlen) - >>= fun () -> if recvlen <= maxlen - then Lwt.return (acc ^ (Bytes.to_string (Bytes.sub str 0 recvlen))) - else _read sock (acc ^ (Bytes.to_string (Bytes.sub str 0 recvlen))) - in _read sock "" + >>= fun () -> let acc = (acc ^ (Bytes.to_string (Bytes.sub str 0 recvlen))) in + if recvlen <= maxlen + then Lwt.return acc + else _read sock acc in + _read sock String.empty + >>= fun _ -> match Relation.write_and_retrieve() with | Ok results -> return results | Error err -> return err let rec socket_read sock = + (* (Int32.of_int (String.length results))) *) Lwt_unix.accept sock >>= fun (client, _) -> client_read client 512 - >>= fun results -> Lwt_io.write_line Lwt_io.stdout results - >>= fun () -> return results + (* >>= fun results -> Lwt_unix.send client (Data_encoding.Binary.to_bytes_exn Data_encoding.Encoding.int32 5l) 0 1 [] *) >>= fun results -> Lwt_unix.send client (Bytes.of_string results) 0 (String.length results) [] >>= fun _ -> Lwt_unix.wait_write client >>= fun () -> Lwt_unix.close client |
