JGroups UDP multicast 救急!
请教一下大侠有关 JGroups UDP multicast的问题:1. 发送端和接收端都必须要用JGroups才可以互相通讯吗, 如果发送端用JGroups, 接收端用普通JAVA API, 或者反过来的话, 可以通讯吗?(我测试的结果是不可以通讯, 不知道JGroups是不是像MQ那样, 发送端和接收端都得用它, 还是我测试不正确?)
2. 局域网内接收不到消息:
在一台机子上, 发送端用 JGroups UDP multicast 发送消息, 如果接收端也在同一台机子上, 则可以接收到消息. 如果发送端放在A机子上, 接收端放在B机子上(A和B都在同一局域网内), 则收不到消息, 为什么呢? (配置文件的内容在下面)
3. 消息丢包/重发的问题:
在消息发送频率高的情况下, 发送端发送的消息为msg1, msg2, msg3, msg4, msg5, msg6, msg7, msg8, msg9, msg10, msg11, 但是在接收端收到的消息可能为 msg3, msg3, msg3, msg5, msg5, msg7, msg7, msg9, msg9, msg11, msg11. 接收端收到的消息中, 有些重复, 有些丢失, 是不是配置方面的问题呢?
配置文件如下:
我把用到的配置文件也贴出来吧(udp.xml):
<UDP ip_mcast="true"
bind_addr="127.0.0.1"
mcast_addr="${jgroups.udp.mcast_addr:239.9.9.9}"
mcast_port="${jgroups.udp.mcast_port:45588}"
tos="8"
ucast_recv_buf_size="20M"
ucast_send_buf_size="640K"
mcast_recv_buf_size="25M"
mcast_send_buf_size="640K"
loopback="true"
discard_incompatible_packets="true"
max_bundle_size="64K"
max_bundle_timeout="30"
ip_ttl="${jgroups.udp.ip_ttl:8}"
enable_bundling="true"
enable_diagnostics="true"
thread_naming_pattern="cl"
timer_type="new"
timer.min_threads="4"
timer.max_threads="10"
timer.keep_alive_time="5000"
timer.queue_max_size="500"
timer.rejection_policy="abort"
thread_pool.enabled="true"
thread_pool.min_threads="10"
thread_pool.max_threads="100"
thread_pool.keep_alive_time="5000"
thread_pool.queue_enabled="true"
thread_pool.queue_max_size="50000"
thread_pool.rejection_policy="discard"
oob_thread_pool.enabled="true"
oob_thread_pool.min_threads="5"
oob_thread_pool.max_threads="100"
oob_thread_pool.keep_alive_time="5000"
oob_thread_pool.rejection_policy="Run"/>
<PING timeout="2000"
num_initial_members="100"
break_on_coord_rsp="true" />
<MERGE2 max_interval="30000"
min_interval="10000"
merge_fast="false"/>
<FD_SOCK/>
<FD_ALL/>
<VERIFY_SUSPECT timeout="1500" />
<BARRIER />
<pbcast.NAKACK exponential_backoff="300"
xmit_stagger_timeout="200"
use_mcast_xmit="true"
discard_delivered_msgs="true"/>
<UNICAST2 exponential_backoff="500"/>
<pbcast.STABLE stability_delay="2000" desired_avg_gossip="60000"
max_bytes="4M"
cap="0.1"/>
<pbcast.GMS print_local_addr="true"
join_timeout="10000"
view_bundling="true"
max_bundling_time="1000"
merge_timeout="5000"
resume_task_timeout="15000"
/>
<UFC max_credits="4M"
min_threshold="0.4"/>
<MFC max_credits="4M"
min_threshold="0.4"/>
<FRAG2 frag_size="60K" />
<pbcast.STATE_TRANSFER />
发送端的主要代码:
byte[] sentBytes = {xxxxxxx} // 生成发送字节数组的内容, 代码省略.
JChannel channel = new JChannel(new File(PathUtils.find("conf/udp.xml")));
channel.connect("my_jgroups");
while (true) {
channel.send(null, sentBytes);
Thread.sleep(1000);
}
接收端的主要代码:
JChannel channel = new JChannel(new File(PathUtils.find("conf/udp.xml")));
channel.setReceiver(new ReceiverAdapter() {
@Override
public void receive(Message message) {
System.out.println("received : " + new String(message.getBuffer()));
}
@Override
public void viewAccepted(View view1) {
System.out.println("received view : " + view1);
}
});
channel.connect("my_jgroups");
各路神仙, 大侠帮帮忙....谢谢 --------------------编程问答-------------------- 补充一下:
1. 当消息的发送频率比较高时, 才会出现 "3. 消息丢包/重发的问题" 这种情况.
2. "2. 局域网内接收不到消息 "---- 我用普通的JAVA API写的 multicast 在局域网内通讯是没有问题的. --------------------编程问答-------------------- --------------------编程问答-------------------- 自己顶上去. --------------------编程问答-------------------- 很少接触到UPD这些。 --------------------编程问答-------------------- --------------------编程问答-------------------- <pbcast.NAKACK exponential_backoff="300" xmit_stagger_timeout="200" use_mcast_xmit="true" discard_delivered_msgs="true"/> <UNICAST2 exponential_backoff="500"/>
这两个协议是保证消息顺序的。
discard_delivered_msgs="false" --------------------编程问答-------------------- 除 --------------------编程问答-------------------- ip_mcast="true"
用这个属性,表示用多播发送。你在平板电脑上跑过么?
我将这个设置为true,在平板上跑不动 --------------------编程问答-------------------- 楼主的发送速度有点慢啊,丢包情况怎么样啊,我最近尝试300kb/s的速度,包丢就很严重了 --------------------编程问答--------------------
afasdfsdf[code=c][code=c]asdfasdfa[/code][/code]
补充:Java , Java EE