Java到Erlang的消息

Han*_*ken 6 erlang integration erlang-otp jinterface

我正在使用Java中的GUI在Erlang中创建应用程序.我已经成功地建立语言之间的连接,但现在我需要(我猜)从Java将消息发送到二郎,我每次例如按下一个按钮的时间.

这是正确的方法吗?

这样的消息怎么样?

我发现这个形式整合了几个不错的网站,但我觉得我不是让一切.

http://www.trapexit.org/How_to_communicate_java_and_erlang

Pee*_*ger 3

如果 jinterface 太复杂,您可能只需在 open_port 上使用 packet 选项并使用

byte[] in_buf = new byte[256];
byte[] out_buf = new byte[256];
int in_count = System.in.read ();
int offset = 0; 
do
    {
        int c = System.in.read (in_buf, offset, in_count-offset);
        offset += c;
    }
while (offset < in_count);
Run Code Online (Sandbox Code Playgroud)

要从 erlang 读取数据包并写入,请使用:

System.out.write(out_count);
System.out.write(out_buf, 0, out_count);
Run Code Online (Sandbox Code Playgroud)

在 erlang 方面,这将与

open_port({spawn, "<path-to-java> -cp <classpath> your-java-prog", 
          [{packet, 1}]).
Run Code Online (Sandbox Code Playgroud)

如果您需要更大的数据包,请使用 {packet, 2} 或 {packet, 4} 并调整 java.lang. 在数据包内部,您可以在双方上运行您喜欢的任何协议。