need better way to communicate between c node and erlang node
suresh saragadam
sureshsaragadam@REDACTED
Sun Oct 17 07:12:49 CEST 2004
Hi,
After long time back i again started working with Erlang,
i need to communicate between C Node and Erlang Node, i think this
code should do well,
here do i have to keep trap on the socket i.e. 'sockfd'
http://www.erlang.se/doc/doc-5.0.1/doc/tutorial/cnode_s.c
I tested this example link above, it is working fine, but here i want
to eliminate the use of this fun 'int my_listen(int port)' is it
opossible, and i want to make my code accoding to the doc here
C:\Program Files\erl5.3.6.3\lib\erl_interface-3.4.5\doc\html\part_erl_interface_frame.html
This is what the code i want to make it run.
#include <stdio.h>
#include <winsock2.h>
#include <erl_interface.h>
#include <ei.h>
#define SELF(fd) erl_mk_pid(erl_thisnodename(),fd,0,erl_thiscreation())
extern const char *erl_thisnodename(void);
extern short erl_thiscreation(void);
int main()
{
int sockfd;
int conn_id = 100;
int creation = 1;
char *cookie = "secretcookie";
char *nodename="cnode@REDACTED";
ETERM *arr[2], *cmsg;
erl_init(NULL, 0);
erl_connect_init(conn_id, cookie, creation);
if ((sockfd = erl_connect(nodename)) < 0)
erl_err_quit("ERROR: erl_connect failed");
else
printf("\nConnection Established . . .");
printf("\n almost done 1 ");
arr[0] = SELF(sockfd);
arr[1] = erl_mk_atom("Hello world");
cmsg = erl_mk_tuple(arr, 2);
printf("\n almost done 2");
if(erl_reg_send(sockfd, "enode_server", cmsg) == 0)
erl_err_sys("erl_reg_send");
printf("\n almost done 3");
printf("\nmessage sent");
erl_free_term(cmsg);
return 0;
}
thanks
suresh saragadam
More information about the erlang-questions
mailing list