File: udp_echo_server.ml

package info (click to toggle)
ocaml-luv 0.5.14-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,504 kB
  • sloc: ml: 11,130; makefile: 6,223; sh: 4,592; ansic: 1,517; python: 38
file content (15 lines) | stat: -rw-r--r-- 481 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
let () =
  let address = Luv.Sockaddr.ipv4 "127.0.0.1" 7000 |> Result.get_ok in
  let server = Luv.UDP.init () |> Result.get_ok in
  ignore (Luv.UDP.bind server address);

  Luv.UDP.recv_start server begin function
    | Error e ->
      Printf.eprintf "Receive error: %s\n" (Luv.Error.strerror e)
    | Ok (_, None, _) ->
      ()
    | Ok (buffer, Some client_address, _flags) ->
      Luv.UDP.send server [buffer] client_address ignore
  end;

  ignore (Luv.Loop.run () : bool)