[erlang-questions] Erlang.NET mbox doesn't receive message

Martin Janiczek <>
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)?


Relevant part of server code:
loop() ->
   io:format("~nwaiting for msgs~n"),
     {Client, msg_from_client} ->
       io:format("got msg from client ~p~n", [Client]),
       Client ! msg_from_server,
       io:format("wrote to client~n")

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("", 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("");
       OtpConnection conn = self.connect(other);

       conn.sendRPC("global","sync",new OtpErlangList());

       OtpMbox mbox = me.createMbox(true);

       OtpErlangObject[] arr = {mbox.Self, new 
       OtpErlangTuple msg = new OtpErlangTuple(arr);
       OtpErlangObject[] msg_args = {new OtpErlangAtom("server"), msg};
       Console.WriteLine("About to send");
       Console.WriteLine("Sent, gonna receive");
       OtpErlangObject response = mbox.receive();
       Console.WriteLine("Got it!");


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<>,'',rex}
23:37:55 -    
Sent, gonna receive
23:37:55 - <- SEND {2,'',#Pid<>}
23:37:55 -    {rex,ok}
23:37:55 - <- SEND {2,'',#Pid<>}
23:37:55 -    {rex,#Pid<>}
23:37:55 - <- SEND {2,'',#Pid<>}
23:37:55 -    msg_from_server

More information about the erlang-questions mailing list