1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package net
import (
"runtime"
"testing"
)
func TestMulticastJoinAndLeave(t *testing.T) {
if runtime.GOOS == "windows" {
return
}
addr := &UDPAddr{
IP: IPv4zero,
Port: 0,
}
// open a UDPConn
conn, err := ListenUDP("udp4", addr)
if err != nil {
t.Fatal(err)
}
defer conn.Close()
// try to join group
mcast := IPv4(224, 0, 0, 254)
err = conn.JoinGroup(mcast)
if err != nil {
t.Fatal(err)
}
// try to leave group
err = conn.LeaveGroup(mcast)
if err != nil {
t.Fatal(err)
}
}
func TestJoinFailureWithIPv6Address(t *testing.T) {
addr := &UDPAddr{
IP: IPv4zero,
Port: 0,
}
// open a UDPConn
conn, err := ListenUDP("udp4", addr)
if err != nil {
t.Fatal(err)
}
defer conn.Close()
// try to join group
mcast := ParseIP("ff02::1")
err = conn.JoinGroup(mcast)
if err == nil {
t.Fatal("JoinGroup succeeded, should fail")
}
t.Logf("%s", err)
}
|