Java到Erlang消息 [英] Java to Erlang messages
问题描述
我设法建立了语言之间的连接,但现在我需要(我猜)从Java发送消息到Erlang,每次我按一个按钮。
这是正确的方法吗?
这样的消息怎么样?
我已经找到了一些关于这种整合形式的好网站,但我觉得我没有得到一切。
http://www.trapexit.org/How_to_communicate_java_and_erlang
如果jinterface太复杂,您可能只需在open_port上使用数据包选项,并使用
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);
要从erlang读取数据包并写入使用:
System.out.write(out_count);
System.out.write(out_buf,0,out_count);
在erlang端,这将匹配
open_port({spawn,< path-to-java> -cp< classpath> your-java-prog,
[{packet,1}]) 。
如果需要较大的数据包,请使用{packet,2}或{packet,4} 。
在数据包的内部,您可以双击任何您喜欢的协议。
I'm making a application in Erlang, with a GUI in Java. I've managed to establish a connection between the to languages, but now i need to (i guess) send a message from Java to Erlang, every time I e.g press a button.
Is that the right way to go?
How would such a message look?
I've found a few good sites about this form of integration, but I feel like im not getting everything.
http://www.trapexit.org/How_to_communicate_java_and_erlang
If jinterface is too complicated you might just use the packet option on open_port and use
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);
To read packets from erlang and to write use:
System.out.write(out_count);
System.out.write(out_buf, 0, out_count);
On the erlang side this would match with
open_port({spawn, "<path-to-java> -cp <classpath> your-java-prog",
[{packet, 1}]).
If you need larger packets use {packet, 2} or {packet, 4} and adapt the java. Inside the packets you can run whatever protocol you like on both sides.
这篇关于Java到Erlang消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!