Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
chain33-pai
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
szh
chain33-pai
Commits
20a5e9cf
Commit
20a5e9cf
authored
Jul 28, 2020
by
szh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化获取本地ip流程
parent
2b41b1a9
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
3 deletions
+5
-3
broadcast.go
pkg/app/broadcast.go
+5
-3
No files found.
pkg/app/broadcast.go
View file @
20a5e9cf
...
@@ -26,10 +26,11 @@ func Broadcast() {
...
@@ -26,10 +26,11 @@ func Broadcast() {
panic
(
"no serial no"
)
panic
(
"no serial no"
)
}
}
}
}
ip
,
err
:=
GetRightIP
()
ip
s
,
err
:=
GetRightIPs
()
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
err
)
panic
(
err
)
}
}
ip
:=
ips
[
0
]
// 这里设置发送者的IP地址,自己查看一下自己的IP自行设定
// 这里设置发送者的IP地址,自己查看一下自己的IP自行设定
laddr
:=
net
.
UDPAddr
{
laddr
:=
net
.
UDPAddr
{
...
@@ -49,10 +50,11 @@ func Broadcast() {
...
@@ -49,10 +50,11 @@ func Broadcast() {
}
}
for
{
for
{
//ip 会变化
//ip 会变化
ip
,
err
=
GetRightIP
()
ip
s
,
err
=
GetRightIPs
()
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
err
)
panic
(
err
)
}
}
ip
=
ips
[
0
]
if
runningAddr
!=
nil
&&
runningAddr
.
IP
.
String
()
!=
ip
.
IP
.
String
()
{
if
runningAddr
!=
nil
&&
runningAddr
.
IP
.
String
()
!=
ip
.
IP
.
String
()
{
laddr
=
net
.
UDPAddr
{
laddr
=
net
.
UDPAddr
{
...
@@ -108,7 +110,7 @@ func GetRightIP() (ipv4 *net.IPNet, err error) {
...
@@ -108,7 +110,7 @@ func GetRightIP() (ipv4 *net.IPNet, err error) {
return
ip
,
err
return
ip
,
err
}
}
func
GetRightI
p
s
()
(
ipv4s
[]
*
net
.
IPNet
,
err
error
)
{
func
GetRightI
P
s
()
(
ipv4s
[]
*
net
.
IPNet
,
err
error
)
{
ips
:=
make
([]
*
net
.
IPNet
,
0
)
ips
:=
make
([]
*
net
.
IPNet
,
0
)
interfaces
,
err
:=
net
.
Interfaces
()
interfaces
,
err
:=
net
.
Interfaces
()
if
err
!=
nil
{
if
err
!=
nil
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment