Skip to content

Commit

Permalink
Add usage examples to README.md
Browse files Browse the repository at this point in the history
Signed-off-by: John Else <john.else@gmail.com>
  • Loading branch information
johnelse committed Feb 8, 2016
1 parent c914b77 commit 1878d4f
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,41 @@ Dependencies:
* [ocplib-endian](https://github.com/OCamlPro/ocplib-endian)
* [oUnit](http://ounit.forge.ocamlcore.org/)
* [rresult](https://github.com/dbuenzli/rresult)

Usage
=====

If you just want to parse and serialise OSC packets, use the `Osc.Codec`
module:

``` ocaml
# require "osc";;
# open Osc.Types;;
# let data = Osc.Codec.of_packet (Message {address = "/hello/world"; arguments = [Int32 123l; String "foo"]});;
val data : bytes = "/hello/world\000\000\000\000,is\000\000\000\000{foo\000"
# let packet = Osc.Codec.to_packet data;;
val packet : (packet, [ `Missing_typetag_string | `Unsupported_typetag of char ]) Rresult.result =
Rresult.Ok (Message {address = "/hello/world"; arguments = [Int32 123l; String "foo"]})
```

To simplify sending and receiving OSC packets over the network, the modules
`Osc_lwt` and `Osc_unix` are available:

``` ocaml
# require "osc.lwt";;
# require "lwt.syntax";;
# open Osc.Types;;
# lwt client = Osc_lwt.Udp.Client.create ();;
val client : Osc_lwt.Udp.Client.t = <abstr>
# let addr = Unix.ADDR_INET (Unix.inet_addr_of_string "127.0.0.1", 57120);;
val addr : Lwt_unix.sockaddr = Unix.ADDR_INET (<abstr>, 57120)
# lwt () = Osc_lwt.Udp.Client.send client addr (Message {address = "/hello/world"; arguments = [Int32 123l; String "foo"]});;
```

0 comments on commit 1878d4f

Please sign in to comment.