import com.ericsson.otp.erlang.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service public class ErlangService { @Autowired private OtpNode otpNode; public void sendMessageToErlangNode(String nodeName, String message) { try { OtpPeer peer = new OtpPeer(nodeName); OtpMbox mbox = otpNode.createMbox(); mbox.send(peer, new OtpErlangString(message)); System.out.println("Message sent to Erlang node"); } catch (Exception e) { e.printStackTrace(); } } } import com.ericsson.otp.erlang.*; import com.ericsson.otp.stdlib.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service public class ErlangService { @Autowired private OtpNode otpNode; public void connectToErlangNode(String nodeName) { try { OtpPeer peer = new OtpPeer(nodeName); OtpConnection connection = otpNode.connect(peer); System.out.println("Connected to Erlang node"); OtpErlangObject receivedObject = connection.receive(); if (receivedObject instanceof OtpErlangTuple) { OtpErlangTuple receivedTuple = (OtpErlangTuple) receivedObject; System.out.println("Received tuple from Erlang node: " + receivedTuple.toString()); } connection.sendRPC("erlang", "node", new OtpErlangList()); } catch (Exception e) { e.printStackTrace(); } } }


上一篇:
下一篇:
切换中文