Skip to content

Instantly share code, notes, and snippets.

@Leonidas-from-XIV
Created July 27, 2017 09:49
Show Gist options
  • Save Leonidas-from-XIV/e4b14f233200fc655451d321dd102192 to your computer and use it in GitHub Desktop.
Save Leonidas-from-XIV/e4b14f233200fc655451d321dd102192 to your computer and use it in GitHub Desktop.
Sending a UDP packet is… complex?
open Core.Std
open Async.Std
(* let buf = Iobuf.of_string "hello hest\n" *)
let addr = Unix.Inet_addr.of_string "127.0.0.1"
let socket_addr = Unix.Socket.Address.Inet.create addr ~port:2115
let _ =
let open Or_error.Monad_infix in
Udp.sendto () >>| fun fd iobuf addr ->
(* ??? *)
Deferred.unit
@copy
Copy link

copy commented Jul 27, 2017

let sendto_sync: (_ ->
 (Core.read, Core.Iobuf.seek) Core.Iobuf.t -> _) =
  Or_error.ok_exn @@ Udp.sendto_sync ()

let _ =
  let s = Socket.create Socket.Type.udp in
  sendto_sync (Socket.fd s) ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment