修改模拟半实物服务逻辑
This commit is contained in:
parent
23d441981c
commit
11ce706969
@ -4,6 +4,8 @@ import (
|
|||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -24,9 +26,23 @@ var trainRun bool
|
|||||||
// var IP = net.IPv4(192, 168, 3, 7)
|
// var IP = net.IPv4(192, 168, 3, 7)
|
||||||
// var SendIP = net.IPv4(192, 168, 3, 7)
|
// var SendIP = net.IPv4(192, 168, 3, 7)
|
||||||
var IP = net.IPv4(127, 0, 0, 1)
|
var IP = net.IPv4(127, 0, 0, 1)
|
||||||
var SendIP = net.IPv4(127, 0, 0, 1)
|
var SendIP = "127.0.0.1"
|
||||||
|
var tick = 10 * time.Millisecond
|
||||||
|
|
||||||
|
// 参数1:ip 参数2:间隔
|
||||||
func main() {
|
func main() {
|
||||||
|
if len(os.Args) >= 2 && os.Args[1] != "" {
|
||||||
|
SendIP = os.Args[0]
|
||||||
|
}
|
||||||
|
if len(os.Args) >= 3 && os.Args[2] != "" {
|
||||||
|
i, err := strconv.Atoi(os.Args[1])
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
tick = time.Duration(i) * time.Millisecond
|
||||||
|
}
|
||||||
|
fmt.Println("目的IP:", SendIP)
|
||||||
|
fmt.Println("间隔:", tick, "毫秒")
|
||||||
listen, err := net.ListenUDP("udp", &net.UDPAddr{
|
listen, err := net.ListenUDP("udp", &net.UDPAddr{
|
||||||
IP: IP,
|
IP: IP,
|
||||||
Port: 5000,
|
Port: 5000,
|
||||||
@ -36,10 +52,10 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
tick := time.Tick(10 * time.Millisecond)
|
tick := time.Tick(tick)
|
||||||
remoteAddr, err2 := net.Dial("udp", SendIP.String()+":"+"10000")
|
remoteAddr, err := net.Dial("udp", fmt.Sprintf("%s:%d", SendIP, 10000))
|
||||||
if err2 != nil {
|
if err != nil {
|
||||||
fmt.Printf("Dial udp err: %v", err2)
|
fmt.Printf("Dial udp err: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//remoteAddr := &net.UDPAddr{IP: SendIP, Port: 10000}
|
//remoteAddr := &net.UDPAddr{IP: SendIP, Port: 10000}
|
||||||
|
Loading…
Reference in New Issue
Block a user