Erlang Nodes and C Nodes

A step by step guide for integrating C into your Erlang project

Image Credit: Cara Fuller

Erlang Nodes

On the other hand, to understand C Nodes, we need to understand Erlang Nodes. Erlang Nodes are the runtime systems. When you call erl in terminal you create an Erlang node. Erlang Nodes can communicate through send and receive constructors. So you can communicate between nodes using pid like two process communicating in the same node. But if you want to use registered names, you have to indicate the node beside the registered process name because registered names are local to each node. You can name your nodes by -name or -sname(stands for short name) flags after erl command on terminal.

C Nodes

We can move on to C nodes because we have covered Erlang nodes at basic level. A C node is established using Erlang Interface Library in c. First, you have to initialize Erlang interface.

const char *nodename = ei_thishostname(&ec);
char *erlang_node_name = "node1@yusufpro";
int fd = ei_connect(&ec, erlang_node_name);
ei_x_buff &buff_object;
ei_reg_send(&ec, fd, <process_name> , buff_object.buff, buff_object.index);
(node1@YusufPro)1> {any,c1@YusufPro} ! #{first => [1,-1],second => {1,2}}.
erlang_msg msg;
ei_xreceive_msg(fd, &msg, &buff_object);


Erlang is very good for learning purely functional programming. However, highly complex array manipulation can be a big deal. C nodes overcome this obstacle and make the language better.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store