Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
3ff03ce6
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
3ff03ce6
编写于
3月 10, 2010
作者:
C
chegar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
Reviewed-by: alanb
上级
ff314cac
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
61 addition
and
56 deletion
+61
-56
test/java/net/MulticastSocket/NoLoopbackPackets.java
test/java/net/MulticastSocket/NoLoopbackPackets.java
+61
-56
未找到文件。
test/java/net/MulticastSocket/NoLoopbackPackets.java
浏览文件 @
3ff03ce6
...
...
@@ -29,9 +29,7 @@
import
java.util.*
;
import
java.net.*
;
public
class
NoLoopbackPackets
{
private
static
int
PORT
=
9001
;
private
static
String
osname
;
static
boolean
isWindows
()
{
...
...
@@ -68,40 +66,47 @@ public class NoLoopbackPackets {
return
;
}
// we will send packets to three multicast groups :-
// 224.1.1.1, ::ffff:224.1.1.2, and ff02::1:1
//
List
<
SocketAddress
>
groups
=
new
ArrayList
<
SocketAddress
>();
groups
.
add
(
new
InetSocketAddress
(
InetAddress
.
getByName
(
"224.1.1.1"
),
PORT
));
groups
.
add
(
new
InetSocketAddress
(
InetAddress
.
getByName
(
"::ffff:224.1.1.2"
),
PORT
));
groups
.
add
(
new
InetSocketAddress
(
InetAddress
.
getByName
(
"ff02::1:1"
),
PORT
));
Thread
sender
=
new
Thread
(
new
Sender
(
groups
));
sender
.
setDaemon
(
true
);
// we want sender to stop when main thread exits
sender
.
start
();
// Now try to receive multicast packets. we should not see any of them
// since we disable loopback mode.
//
MulticastSocket
msock
=
new
MulticastSocket
(
PORT
);
msock
.
setSoTimeout
(
5000
);
// 5 seconds
byte
[]
buf
=
new
byte
[
1024
];
DatagramPacket
packet
=
new
DatagramPacket
(
buf
,
0
,
buf
.
length
);
MulticastSocket
msock
=
null
;
List
<
SocketAddress
>
failedGroups
=
new
ArrayList
<
SocketAddress
>();
for
(
SocketAddress
group
:
groups
)
{
msock
.
joinGroup
(
group
,
null
);
try
{
msock
.
receive
(
packet
);
try
{
msock
=
new
MulticastSocket
();
int
port
=
msock
.
getLocalPort
();
// we will send packets to three multicast groups :-
// 224.1.1.1, ::ffff:224.1.1.2, and ff02::1:1
//
List
<
SocketAddress
>
groups
=
new
ArrayList
<
SocketAddress
>();
groups
.
add
(
new
InetSocketAddress
(
InetAddress
.
getByName
(
"224.1.1.1"
),
port
));
groups
.
add
(
new
InetSocketAddress
(
InetAddress
.
getByName
(
"::ffff:224.1.1.2"
),
port
));
groups
.
add
(
new
InetSocketAddress
(
InetAddress
.
getByName
(
"ff02::1:1"
),
port
));
Thread
sender
=
new
Thread
(
new
Sender
(
groups
));
sender
.
setDaemon
(
true
);
// we want sender to stop when main thread exits
sender
.
start
();
// Now try to receive multicast packets. we should not see any of them
// since we disable loopback mode.
//
msock
.
setSoTimeout
(
5000
);
// 5 seconds
byte
[]
buf
=
new
byte
[
1024
];
DatagramPacket
packet
=
new
DatagramPacket
(
buf
,
0
,
buf
.
length
);
for
(
SocketAddress
group
:
groups
)
{
msock
.
joinGroup
(
group
,
null
);
try
{
msock
.
receive
(
packet
);
// it is an error if we receive something
failedGroups
.
add
(
group
);
}
catch
(
SocketTimeoutException
e
)
{
// we expect this
}
// it is an error if we receive something
failedGroups
.
add
(
group
);
}
catch
(
SocketTimeoutException
e
)
{
// we expect this
msock
.
leaveGroup
(
group
,
null
);
}
msock
.
leaveGroup
(
group
,
null
);
}
finally
{
if
(
msock
!=
null
)
try
{
msock
.
close
();
}
catch
(
Exception
e
)
{}
}
if
(
failedGroups
.
size
()
>
0
)
{
...
...
@@ -111,36 +116,36 @@ public class NoLoopbackPackets {
throw
new
RuntimeException
(
"test failed."
);
}
}
}
class
Sender
implements
Runnable
{
private
List
<
SocketAddress
>
sendToGroups
;
public
Sender
(
List
<
SocketAddress
>
groups
)
{
sendToGroups
=
groups
;
}
static
class
Sender
implements
Runnable
{
private
List
<
SocketAddress
>
sendToGroups
;
public
void
run
(
)
{
byte
[]
buf
=
"hello world"
.
getBytes
()
;
List
<
DatagramPacket
>
packets
=
new
ArrayList
<
DatagramPacket
>();
public
Sender
(
List
<
SocketAddress
>
groups
)
{
sendToGroups
=
groups
;
}
try
{
for
(
SocketAddress
group
:
sendToGroups
)
{
DatagramPacket
packet
=
new
DatagramPacket
(
buf
,
buf
.
length
,
group
);
packets
.
add
(
packet
);
}
public
void
run
()
{
byte
[]
buf
=
"hello world"
.
getBytes
();
List
<
DatagramPacket
>
packets
=
new
ArrayList
<
DatagramPacket
>();
MulticastSocket
msock
=
new
MulticastSocket
();
msock
.
setLoopbackMode
(
true
);
// disable loopback mode
for
(;;)
{
for
(
DatagramPacket
packet
:
packets
)
{
msock
.
send
(
packet
);
try
{
for
(
SocketAddress
group
:
sendToGroups
)
{
DatagramPacket
packet
=
new
DatagramPacket
(
buf
,
buf
.
length
,
group
);
packets
.
add
(
packet
);
}
Thread
.
currentThread
().
sleep
(
1000
);
// 1 second
MulticastSocket
msock
=
new
MulticastSocket
();
msock
.
setLoopbackMode
(
true
);
// disable loopback mode
for
(;;)
{
for
(
DatagramPacket
packet
:
packets
)
{
msock
.
send
(
packet
);
}
Thread
.
sleep
(
1000
);
// 1 second
}
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录