# Async rpc: how to make a persistant rpc connection

**URL:** <https://discuss.ocaml.org/t/async-rpc-how-to-make-a-persistant-rpc-connection/6536>\
**Category:** Learning\
**Tags:** core\
**Created:** [October 1, 2020, 4:45pm UTC](https://discuss.ocaml.org/t/async-rpc-how-to-make-a-persistant-rpc-connection/6536 "2020-10-01T16:45:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cjen1](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/cjen1/32/1731_2.png) [@Cjen1](https://discuss.ocaml.org/u/Cjen1)\
**Post date:** [October 1, 2020, 4:45pm UTC](https://discuss.ocaml.org/t/async-rpc-how-to-make-a-persistant-rpc-connection/6536/1 "2020-10-01T16:45:01Z")

</div>

Hi all I’m trying to get my head around how the Async ecosystem connects together.

I’m aiming to have a persistant rpc connection to some set of services. I can see that there is a way to create persistant connections: `Persistant_connection_kernel`, however it isn’t obvious to me how use that, and additionally how to inject the result into the rpc connection system: `Rpc.Connection.create`.

I can see that there is an `create` method which takes a `Transport.t` though I can’t quite see how to pipe everything through (additionally it looks like there are two `create` methods which should alias each other?)

---

<div class="post-metadata">

**Author:** ![bcc32](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/bcc32/32/203_2.png) [@bcc32](https://discuss.ocaml.org/u/bcc32)\
**Post date:** [October 1, 2020, 5:10pm UTC](https://discuss.ocaml.org/t/async-rpc-how-to-make-a-persistant-rpc-connection/6536/2 "2020-10-01T17:10:14Z")

</div>

[`Async_rpc_kernel.Persistent_connection.Rpc`](https://ocaml.janestreet.com/ocaml-core/latest/doc/async_rpc_kernel/Async_rpc_kernel/Persistent_connection/index.html#module-Rpc) is a pre-packaged persistent connection module which gives you `Rpc.Connection.t`s. It uses `Host_and_port.t` as the address type and `Rpc.Connection.t` as the connection type.

For example, you could do something like:

```ocaml
let _ =
  let persistent_connection =
    Async_rpc_kernel.Persistent_connection.Rpc.create
      ~server_name:"RPC server"
      ~connect:(fun host_and_port ->
        Rpc.Connection.client
          (Tcp.Where_to_connect.of_host_and_port host_and_port))
      (fun () -> server_address)
  in
  let%bind conn = Async_rpc_kernel.Persistent_connection.Rpc.connected persistent_connection in
  (* do something with the RPC connection *)

```

---

<div class="post-metadata">

**Author:** ![Cjen1](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/cjen1/32/1731_2.png) [@Cjen1](https://discuss.ocaml.org/u/Cjen1)\
**Post date:** [October 1, 2020, 5:12pm UTC](https://discuss.ocaml.org/t/async-rpc-how-to-make-a-persistant-rpc-connection/6536/3 "2020-10-01T17:12:16Z")

</div>

Brilliant thanks!! That is exactly what I was looking for! I think I was looking at an old version of the API…
