[erlang-questions] : First send from JInterface ok, second one blocs??

Raimo Niskanen <>
Tue May 13 10:57:21 CEST 2008


Since you gave no example code I give you counterexample code.
I have done a simple RPC call example:
======================================
import com.ericsson.otp.erlang.*;

public class jrpc {
    public static void main(String[] argv) {
	System.out.println("jrpc hello world!");
	
	try {
	    OtpNode node = new OtpNode(argv[0], argv[1]);
	    OtpMbox mbox = node.createMbox();
	    
	    OtpErlangObject[] call = new OtpErlangObject[5];
	    call[0] = new OtpErlangAtom("call");
	    call[1] = new OtpErlangAtom("erlang");
	    call[2] = new OtpErlangAtom("display");
	    call[3] = new OtpErlangList(new OtpErlangAtom(argv[3]));
	    call[4] = new OtpErlangAtom("user");
	    
	    OtpErlangObject[] req = new OtpErlangObject[2];
	    req[0] = mbox.self();
	    req[1] = new OtpErlangTuple(call);
	    
	    OtpErlangTuple request = new OtpErlangTuple(req);
	    System.out.println("Sending: "+request);
	    mbox.send("rex", argv[2], request);
	    OtpErlangObject reply = mbox.receive();
	    System.out.println("Received: "+reply);
	    
	    System.out.println("Sending: "+request);
	    mbox.send("rex", argv[2], request);
	    reply = mbox.receive();
	    System.out.println("Received: "+reply);
	} catch (java.io.IOException e) {
	    System.out.println("Exited: "+e);
	} catch (OtpErlangException e) {
	    System.out.println("Exited: "+e);
	}
    }
}
======================================



I compile it and then start an erlang node "". Then:

$java -DOtpConnection.trace=4 jrpc  `cat ~/.erlang.cookie`  hello
jrpc hello world!
-> PUBLISH (r4)  port=10793
<- OK
Sending: {#Pid<>,{call,erlang,display,[hello],user}}
-> LOOKUP (r4) 
<- PORT 29584
-> MD5 CONNECT TO localhost:29584
-> HANDSHAKE sendName flags=3332 dist=5 local=
<- HANDSHAKE recvStatus (ok) local=
<- HANDSHAKE recvChallenge from= challenge=-250041024 local=
-> HANDSHAKE sendChallengeReply challenge=2117997141 digest=82c7630368bc22523d0333142822ac34 local=
<- HANDSHAKE recvChallengeAck from= digest=b4d2aef7cb4a2e116842ff944e0a874e local=
-> REG_SEND {6,#Pid<>,'',rex}
   {#Pid<>,{call,erlang,display,[hello],user}}
<- SEND {2,'',#Pid<>}
   {rex,true}
Received: {rex,true}
Sending: {#Pid<>,{call,erlang,display,[hello],user}}
-> REG_SEND {6,#Pid<>,'',rex}
   {#Pid<>,{call,erlang,display,[hello],user}}
<- SEND {2,'',#Pid<>}
   {rex,true}
Received: {rex,true}

On  it prints `hello' twice in the console. All is well.
If I on the other hand use the wrong connection cookie:

$ java -DOtpConnection.trace=4 jrpc  `cat ~/.erlang.cookie`XXX  hello
jrpc hello world!
-> PUBLISH (r4)  port=1075
<- OK
Sending: {#Pid<>,{call,erlang,display,[hello],user}}
-> LOOKUP (r4) 
<- PORT 29584
-> MD5 CONNECT TO localhost:29584
-> HANDSHAKE sendName flags=3332 dist=5 local=
<- HANDSHAKE recvStatus (ok) local=
<- HANDSHAKE recvChallenge from= challenge=-1931661201 local=
-> HANDSHAKE sendChallengeReply challenge=-430223828 digest=02405e8c4263de8ac92f09ec82804b07 local=
-> CLOSE



The  apparently hangs in the mbox.send(), and
 prints:

=ERROR REPORT==== 13-May-2008::10:43:05 ===
** Connection attempt from disallowed node  ** 



On Mon, May 12, 2008 at 07:32:22PM +0200, Alexander Lamb wrote:
> Some more information: even if I create a new mailbox before each  
> send, it behaves the same way. Impossible to do a second message send  
> (or a ping). If I restart the java application, even without  
> restarting the erlang server, it again works for the first send.
> 
> Alex
> 
> Le 12 mai 08 à 18:43, Alexander Lamb a écrit :
> 
> > Hello,
> >
> > I have something curious happening when sending messages to the rex
> > rpc server.
> >
> > The first time I send a message, everything is ok. The second time, it
> > blocs and I finally get a timeout (e.g. the response is null).
> >
> > I activated the trace, and here is what I get:
> >
> > -> PUBLISH (r4)  port=55076
> > <- OK
> > -> LOOKUP (r4) 
> > <- PORT 55021
> > -> MD5 CONNECT TO kirk.local:55021
> > -> HANDSHAKE sendName flags=3332 dist=5 local=
> > <- HANDSHAKE recvStatus (ok) local=
> > <- HANDSHAKE recvChallenge from= challenge=1257096912
> > local=
> > -> HANDSHAKE sendChallengeReply challenge=-63103116
> > digest=16202c1233ac821560450cd85550f542 local=
> > <- HANDSHAKE recvChallengeAck from=
> > digest=c223cd415468ff024d0529992ab8ec48 local=

Since you got the "<- HANDSHAKE recvChallengeAck" it 
is not the connection cookie.

> > -> REG_SEND {6,#Pid<>,'',rex}
> >    {#Pid<>,{call,profiles,get_default_menus,
> > [[84,79,80]],user}}
> > <- SEND {2,'',#Pid<>}
> >    {rex,{ok,[{menu,home,{{home,"Home"},[{login,"Login"},
> > {logout,"Logout"},{about,"About"}]}},{menu,patients,
> > {{patients,"Patients"},[]}},{menu,centers,{{centers,"Centers"},
> > [{search,"Search"},{list,"List"}]}},{menu,dashboard,
> > {{dashboard,"Dashboard"},[{enrollment,"Enrollment"},
> > {statistics,"Statistics"},{initiation,"Initiation"}]}}]}}
> > -> LOOKUP (r4) 

Are you initiating another connection to an already
connected node?

> > <- PORT 55021
> > -> MD5 CONNECT TO kirk.local:55021
> > -> HANDSHAKE sendName flags=3332 dist=5 local=

You got thrown out this early. The other node does
not like you. I think it is duplicate connections.
See my example above of sending twice.

> > -> CLOSE
> >
> >
> > So the funny thing is that something is doing a CLOSE. What does that
> > mean??
> >
> > Thanks,
> >
> > Alex
> > _______________________________________________
> > erlang-questions mailing list
> > 
> > http://www.erlang.org/mailman/listinfo/erlang-questions
> >
> 
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list