[erlang-questions] Problems in erl_accept

J Bhanot <>
Fri Feb 1 13:05:41 CET 2008


thanks again Gleber...

I have placed problem of accept at lower priority on my stack as of now...

Now, I am trying to send the a simple "hello world" from my C node to 
Erlang node ---

I have come across 2 ways to do that - 

erl send(fd, to, msg)

where
to is an Erlang term containing the Pid of the intended recipient of the 
message.

Now the query here is is this to PID of my Erlang node (same PID which we 
get by doing ps aux | grep "erlangnode") or this is some other PID

and if this is PID(int) which i get by grep then how do I convert into 
ETerm (think that should be simple, but owing to fact that I am a newbie 
in Erlang - finding it bit difficult at this moment :-()


Second way to send message is:

erl reg send(fd, to, msg)

in which 

to is a string containing the registered name of the intended recipient of 
the message.

Now question is do i need to regsiter my Erlang node...

I have tried doing so by following commands:

 P1 = spawn(fun() -> receive _ -> ok end end).
 global:register_name(test, P1).
global:registered_names().
[test]

Now, I assume that test is regsitered name for the node...

and have tried 

if(erl_reg_send(sockfd, "test", cmsg) == 0)

but this thing is not working - - is there any other way of registering 
the Erlang node and whom with this node regsiter (EPMD???)

Thanks and Regards,
jb




Gleber <> 
02/01/2008 05:22 PM

To
"J Bhanot" <>
cc

Subject
Re: Problems in erl_accept






Sorry. I've never created any C node for erlang, though I don't know
what is the source of the error... Hence You should wait for answers
from more experienced erlangers from the mailing list :)

But my intuition says, that problem is probably in sockfd, since it is
the only socket file descriptor ought to be correct :)

Good luckwith Erlang :) It is fascinating language!

Regards,
Gleb Peregud

On 2/1/08, J Bhanot <> wrote:
> thanks Gleb...
>
> I had to publish my C node and then it was being shown in Erlang node by
> executing this command:
>
> nodes(hidden).
>
> but now when i want it to accept connection - I have added following
> code..
>
> memset((char *) &remote, 0, sizeof(remote));
> if(erl_accept(sockfd, &remote) == ERL_ERROR)
> erl_err_sys("accept");
>
>
> where remote is declared at the top as
>
> ErlConnect remote;
>
> and sockfd is the same socket which I have used in connecting to Erlang
> node, binding/listening and have made this port as non blocking as well
>
> but now when I execute code for C node..
>
> I am getting following error:
>
> accept: Bad file descriptor
>
> Any ideas on that..
>
> Regards,
> jb
>
> ____________________________________________
>
>
>
> Gleber <>
> 02/01/2008 12:01 AM
>
> To
> "J Bhanot" <>, 
> cc
>
> Subject
> Re: [erlang-questions] Erlang C Communication - process completes but
> nodes are not connected
>
>
>
>
>
>
> Hello.
>
> This is my first post to this list, so i'm sorry for any mistakes :)
>
> IIRC, C nodes are hidden nodes, hence net_adm:world() will not show
> them. Use nodes(hidden). to list hidden nodes.
>
> Regards,
> Gleb Peregud
>
> On 1/31/08, J Bhanot <> wrote:
> > Hi,
> >
> > I am using C node as client
> > []
> >
> > #include <stdio.h>
> > #include <signal.h>
> > #include<string.h>
> > #include <sys/socket.h>
> > #include <netinet/in.h>
> > #include <arpa/inet.h>
> > #include <sys/fcntl.h>
> >
> > #include "erl_interface.h"
> > #include "ei.h"
> >
> > #define PORT 6666
> >
> > int sockfd, epmdfd;
> >
> > main()
> > {
> >
> > struct in_addr addr;
> > erl_init(NULL, 0);
> >
> > printf("Initializing ...");
> >         if(!erl_connect_init(69, "SFEWRG34AFDSGAFG35235", 0))
> >                {
> >                 printf("\nerror in initialisation");
> >                 erl_err_sys("erl_connect_init");
> >                 printf("\nafter error in init");
> >                 }
> >         printf(" done.\n");
> >         printf("node=%s, host=%s, alive=%s, creation=%d\n ",
> >                         erl_thisnodename(), erl_thishostname(),
> >                         erl_thisalivename(), erl_thiscreation());
> >
> >
> >
> >
> >     /*This is the short host name outgoing connect routine  */
> >         printf("Connecting ...");
> > usleep(5000);
> > getchar(); //for checking
> >         if((sockfd = erl_connect("")) < 0)
> >
> >       //  if((sockfd = erl_connect("")) < 0)
> > {
> >         printf("in error");
> >         erl_err_sys("erl_connect");
> > }
> >         printf("\nsock = %d\n", sockfd);
> >         erl_err_sys("erl_connect");
> >         printf(" done.\n");
> >
> > }
> >
> > [/code]
> >
> > and Erlang node as server ''
> >
> > Steps to run Erlang node :
> >
> >
> > erl -setcookie SFEWRG34AFDSGAFG35235 -name node1
> > Created a file named $HOME/.hosts.erlang having contents as
> > ''.
> > ''.
> >
> >
> > The output for c file upon execution is
> >
> > [ otp_src_R12B-0]# ./mytest
> > Initializing ... done.
> > node=, host=localhost, alive=c69, creation=0
> >  Connecting ...
> > sock = 3
> > erl_connect: Success
> >
> >
> > but at erlang node when i execute the command :
> > ()8> net_adm:world().
> >
> > i get the output as :
> > []
> >
> > similalry
> >
> > ()9> nodes().
> > []
> > ()10>
> >
> >
> > That is no node is connected to it....
> >
> > Now the point is C node has successfully connected ....
> >
> > Why Erlang node is not showing it as connected....
> >
> > Do we need to register the C node with EPMD even when it is acting as 
a
> > client...
> >
> > Do we need to register Erlang node with EPMD as well and if yes the 
how
> do
> > we do that..
> >
> > Note : I am using putty to connect to single linux server (FC8).
> >
> > Appreciate your help...
> >
> > Many Thanks,
> >
> > jb
> >
> >
> >
> >
> >
> > ____________________________________________
> > =====-----=====-----=====
> > Notice: The information contained in this e-mail
> > message and/or attachments to it may contain
> > confidential or privileged information. If you are
> > not the intended recipient, any dissemination, use,
> > review, distribution, printing or copying of the
> > information contained in this e-mail message
> > and/or attachments to it are strictly prohibited. If
> > you have received this communication in error,
> > please notify us by reply e-mail or telephone and
> > immediately and permanently delete the message
> > and any attachments. Thank you
> >
> >
> >
>
>
> --
> Gleb Peregud
> http://gleber.pl/
>
> "Only two things are infinite, the universe and human stupidity, and
> I'm not sure about the former."
> --  Albert Einstein
>
> ForwardSourceID:NT0000E136
> =====-----=====-----=====
> Notice: The information contained in this e-mail
> message and/or attachments to it may contain
> confidential or privileged information. If you are
> not the intended recipient, any dissemination, use,
> review, distribution, printing or copying of the
> information contained in this e-mail message
> and/or attachments to it are strictly prohibited. If
> you have received this communication in error,
> please notify us by reply e-mail or telephone and
> immediately and permanently delete the message
> and any attachments. Thank you
>
>
>


-- 
Gleb Peregud
http://gleber.pl/

"Only two things are infinite, the universe and human stupidity, and
I'm not sure about the former."
--  Albert Einstein

ForwardSourceID:NT0000E186 
=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain 
confidential or privileged information. If you are 
not the intended recipient, any dissemination, use, 
review, distribution, printing or copying of the 
information contained in this e-mail message 
and/or attachments to it are strictly prohibited. If 
you have received this communication in error, 
please notify us by reply e-mail or telephone and 
immediately and permanently delete the message 
and any attachments. Thank you


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080201/f067e920/attachment.html>


More information about the erlang-questions mailing list