[erlang-questions] Erlang.NET mbox doesn't receive message
Martin Janiczek
martin@REDACTED
Tue Aug 21 23:56:59 CEST 2012
Hi guys,
I'm using Erlang.NET ( https://github.com/takayuki/Erlang.NET ) and am
struggling with receiving message that clearly got sent.
There is Erlang server and C# client. The server listens for {Client,
msg_from_client} and then sends Client ! msg_from_server.
The debug logging from client shows that the message got sent from
server, but somehow the row
OtpErlangObject response = mbox.receive();
doesn't catch it and waits until it gets ^C'd.
I don't really know what does the sync parameter in
OptNode.createMbox(bool sync) do. When I tried to change it from true to
false, instead of waiting indefinitely it throws this exception:
Unhandled Exception: System.NullReferenceException: Object reference
not set to an instance of an object
Why doesn't the code see the message even though it gets sent?
And what should I use in the createMbox(bool sync)?
Thanks!
Relevant part of server code:
------------------------------------------------------------
loop() ->
io:format("~nwaiting for msgs~n"),
receive
{Client, msg_from_client} ->
io:format("got msg from client ~p~n", [Client]),
Client ! msg_from_server,
io:format("wrote to client~n")
end,
loop().
Client code:
------------------------------------------------------------
using System;
using Erlang.NET;
namespace Client
{
public class V01
{
public static void Main(string[] args)
{
OtpNode me = new OtpNode("client", "abc");
//if (!me.ping("server@REDACTED", 2000))
//{
// Console.WriteLine("can't ping!");
// Environment.Exit(1);
//}
// do not ping before the connect!
OtpSelf self = new OtpSelf("client", "abc");
OtpPeer other = new OtpPeer("server@REDACTED");
OtpConnection conn = self.connect(other);
conn.sendRPC("global","sync",new OtpErlangList());
OtpMbox mbox = me.createMbox(true);
OtpErlangObject[] arr = {mbox.Self, new
OtpErlangAtom("msg_from_client")};
OtpErlangTuple msg = new OtpErlangTuple(arr);
OtpErlangObject[] msg_args = {new OtpErlangAtom("server"), msg};
Console.WriteLine("About to send");
conn.sendRPC("global","send",msg_args);
Console.WriteLine("Sent, gonna receive");
OtpErlangObject response = mbox.receive();
Console.WriteLine("Got it!");
Console.WriteLine(response);
Console.WriteLine("Hash:");
Console.WriteLine(response.GetHashCode());
me.close();
Environment.Exit(0);
}
}
}
Server output:
------------------------------------------------------------
waiting for msgs
got msg from client <6547.1.0>
wrote to client
waiting for msgs
Client output (with verbose logging):
------------------------------------------------------------
(... handshakes and whatnot prior to the sending and receiving ...)
About to send
23:37:55 - -> REG_SEND {6,#Pid<client@REDACTED>,'',rex}
23:37:55 -
{#Pid<client@REDACTED>,{call,global,send,[server,{#Pid<client@REDACTED
1.0>,msg_from_client}],user}}
Sent, gonna receive
23:37:55 - <- SEND {2,'',#Pid<client@REDACTED>}
23:37:55 - {rex,ok}
23:37:55 - <- SEND {2,'',#Pid<client@REDACTED>}
23:37:55 - {rex,#Pid<server@REDACTED>}
23:37:55 - <- SEND {2,'',#Pid<client@REDACTED>}
23:37:55 - msg_from_server
More information about the erlang-questions
mailing list