This package provides support for communication with Erlang and representation of Erlang datatypes.

The classes {@link com.ericsson.otp.erlang.OtpPeer}, {@link com.ericsson.otp.erlang.OtpSelf} and {@link com.ericsson.otp.erlang.OtpServer} are used to represent OTP nodes and are neccessary in order to set up communication between the Java thread and a remote node. Once a connection has been established, it is represented by an {@link com.ericsson.otp.erlang.OtpConnection}, through which all communication goes.

The classes {@link com.ericsson.otp.erlang.OtpErlangList}, {@link com.ericsson.otp.erlang.OtpErlangTuple}, {@link com.ericsson.otp.erlang.OtpErlangBinary}, {@link com.ericsson.otp.erlang.OtpErlangAtom}, {@link com.ericsson.otp.erlang.OtpErlangBoolean}, {@link com.ericsson.otp.erlang.OtpErlangByte}, {@link com.ericsson.otp.erlang.OtpErlangChar}, {@link com.ericsson.otp.erlang.OtpErlangDouble}, {@link com.ericsson.otp.erlang.OtpErlangFloat}, {@link com.ericsson.otp.erlang.OtpErlangLong}, {@link com.ericsson.otp.erlang.OtpErlangInt}, {@link com.ericsson.otp.erlang.OtpErlangUInt}, {@link com.ericsson.otp.erlang.OtpErlangShort}, {@link com.ericsson.otp.erlang.OtpErlangUShort}, {@link com.ericsson.otp.erlang.OtpErlangString}, {@link com.ericsson.otp.erlang.OtpErlangObject}, {@link com.ericsson.otp.erlang.OtpErlangPid}, {@link com.ericsson.otp.erlang.OtpErlangPort}, and {@link com.ericsson.otp.erlang.OtpErlangRef} represent the various Erlang datatypes.

Setting up a connection with a remote node is straightforward. You create objects representing the local and remote nodes, then call the local node's {@link com.ericsson.otp.erlang.OtpSelf#connect(com.ericsson.otp.erlang.OtpPeer) connect()} method:

  OtpSelf self = new OtpSelf("client","cookie");
  OtpPeer other = new OtpPeer("server");
  OtpConnection conn = self.connect(other);

The {@link com.ericsson.otp.erlang.OtpSelf OtpSelf} used in the previous example is a client-only node, i.e. it can make outgoing connections but it cannot accept incoming ones. If your Java node also needs to be able to accept incoming connections, you must use an {@link com.ericsson.otp.erlang.OtpServer OtpServer} instead, which can do both:

  OtpServer self = new OtpServer("client","cookie");
  self.publishPort();
  OtpConnection conn = self.accept();

Once the connection is established by one of the above methods ({@link com.ericsson.otp.erlang.OtpSelf#connect(com.ericsson.otp.erlang.OtpPeer) connect()} or {@link com.ericsson.otp.erlang.OtpServer#accept() accept()}), you can use the resulting {@link com.ericsson.otp.erlang.OtpConnection OtpConnection} to send and receive messages:

  OtpErlangAtom msg = new ErlangOtpAtom("hello");
  conn.send("echoserver", msg);
  
  OtpErlangObject reply = conn.receive();
  System.out.println("Received " + reply);