# Erl\_Interface: msg.from pid is not valid to reply to the sender

**URL:** <https://erlangforums.com/t/erl-interface-msg-from-pid-is-not-valid-to-reply-to-the-sender/2530>\
**Category:** Questions / Help\
**Tags:** erl\_interface, cnode, ei\
**Created:** [April 5, 2023, 11:39am UTC](https://erlangforums.com/t/erl-interface-msg-from-pid-is-not-valid-to-reply-to-the-sender/2530 "2023-04-05T11:39:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rbino](https://erlangforums.com/user_avatar/erlangforums.com/rbino/32/1727_2.png) [@rbino](https://erlangforums.com/u/rbino)\
**Post date:** [April 5, 2023, 11:39am UTC](https://erlangforums.com/t/erl-interface-msg-from-pid-is-not-valid-to-reply-to-the-sender/2530/1 "2023-04-05T11:39:28Z")

</div>

I’m experimenting with [`erl_interface`](https://www.erlang.org/doc/apps/erl_interface/) to create a (server, for now) C Node and do some experiments.

I was able to setup the C Node correctly, accept the connection from an Elixir node and receive a message but I found a strange behaviour.

When I call `ei_xreceive_msg`, I expect the `msg` struct to be populated with a `from` pid I can use to reply to the sender, but if I try to use that as argument in `ei_send`, the call fails. If, however, I explicitly send a tuple with the sender pid as first element, i.e. on the Elixir side I basically do

```plaintext
:global.whereis_name(:my_c_node_process)
|> send({self(), :ping})

```

that pid actually works to reply back to the sender.

What am I missing? Is the `msg.from` field used for something different from what I am thinking?

---

<div class="post-metadata">

**Author:** ![saleyn](https://erlangforums.com/user_avatar/erlangforums.com/saleyn/32/1188_2.png) [@saleyn](https://erlangforums.com/u/saleyn)\
**Post date:** [April 5, 2023, 12:44pm UTC](https://erlangforums.com/t/erl-interface-msg-from-pid-is-not-valid-to-reply-to-the-sender/2530/2 "2023-04-05T12:44:39Z")

</div>

`ei_xreceive_msg` provides no information about the sender. If you wanted to receive the sender’s pid, that pid would need to be a part of the term sent to the C node, (e.g. similarly how you do it in your `send/2` example). It would be your responsibility to extract the pid from the term received by `ei_xreceive_msg`. The `from` and `to` fields of the struct are used for a different purpose - when msgtype is ERL\_SEND, ERL\_REG\_SEND, ERL\_LINK, ERL\_UNLINK, ERL\_EXIT, they contain information about the lined/unlinked/registered pid. See [the docs](https://www.erlang.org/doc/man/ei_connect.html#ei_xreceive_msg).

---

<div class="post-metadata">

**Author:** ![rbino](https://erlangforums.com/user_avatar/erlangforums.com/rbino/32/1727_2.png) [@rbino](https://erlangforums.com/u/rbino)\
**Post date:** [April 5, 2023, 1:22pm UTC](https://erlangforums.com/t/erl-interface-msg-from-pid-is-not-valid-to-reply-to-the-sender/2530/3 "2023-04-05T13:22:36Z")

</div>

@saleyn thanks for the help, that’s clearer. One thing I don’t understand though (and I don’t see it explained in the docs) is the difference between `ERL_SEND` and `ERL_REG_SEND` message type - how can I trigger a _registered_ send from the Elixir/Erlang side?  
If I understand correctly in that case then the `msg.from` field would contain the pid of the sender.

This is just curiosity at this point, since I get that in the general case I just have to pass the pid of the caller to reply to it.
