12345678910111213141516171819202122232425262728293031323334353637 |
- package udp
- import (
- mu "mfw/util"
- "net"
- qu "qfw/util"
- sp "spiderutil"
- "sync"
- )
- var Udpclient mu.UdpClient //udp对象
- var ToAdd = &net.UDPAddr{}
- var Ch = make(chan string, 1)
- var IsSendUdp bool
- var SendUdpLock = &sync.Mutex{}
- func InitUdp() {
- Udpclient = mu.UdpClient{Local: sp.Config.LocalUdpPort, BufSize: 1024}
- Udpclient.Listen(func(b byte, data []byte, add *net.UDPAddr) {
- switch b {
- case mu.OP_NOOP: //下个节点回应
- info := string(data)
- qu.Debug(info)
- Ch <- info
- }
- })
- ToAdd = &net.UDPAddr{
- IP: net.ParseIP(sp.Config.UdpAddr),
- Port: sp.Config.UdpPort,
- }
- }
- func SendUdp(by []byte) {
- defer qu.Catch()
- IsSendUdp = true
- Udpclient.WriteUdp(by, mu.OP_TYPE_DATA, ToAdd)
- }
|