本文整理匯總了Golang中net.TCPAddr.Network方法的典型用法代碼示例。如果您正苦於以下問題:Golang TCPAddr.Network方法的具體用法?Golang TCPAddr.Network怎麽用?Golang TCPAddr.Network使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.TCPAddr
的用法示例。
在下文中一共展示了TCPAddr.Network方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Send
// Send DataItems to Zabbix server and wait for response.
// Returns encountered fatal error like I/O and marshalling/unmarshalling.
// Caller should inspect response (and in some situations also Zabbix server log)
// to check if all items are accepted.
func Send(addr *net.TCPAddr, di DataItems) (res *Response, err error) {
b, err := di.Marshal()
if err != nil {
return
}
// Zabbix doesn't support persistent connections, so open/close it every time.
conn, err := net.DialTCP(addr.Network(), nil, addr)
if err != nil {
return
}
defer conn.Close()
_, err = conn.Write(b)
if err != nil {
return
}
buf := make([]byte, 8)
_, err = io.ReadFull(conn, buf[:5])
if err != nil {
return
}
if !bytes.Equal(buf[:5], header) {
err = ErrBadHeader
return
}
_, err = io.ReadFull(conn, buf)
if err != nil {
return
}
var datalen uint64
err = binary.Read(bytes.NewBuffer(buf), binary.LittleEndian, &datalen)
if err != nil {
err = ErrBadHeader
return
}
buf = make([]byte, datalen)
_, err = io.ReadFull(conn, buf)
if err != nil {
return
}
res = new(Response)
err = json.Unmarshal(buf, res)
if err == nil {
m := infoRE.FindStringSubmatch(res.Info)
if len(m) == 3 {
p, _ := strconv.Atoi(m[1])
f, _ := strconv.Atoi(m[2])
res.Processed = p
res.Failed = f
}
}
return
}
示例2: CheckStatusOld
func CheckStatusOld(addr *net.TCPAddr, host string, port uint16) (*MinecraftStatus, time.Duration, error) {
conn, err := net.DialTCP(addr.Network(), nil, addr)
if err != nil {
return nil, 0, fmt.Errorf("CheckStatusOld error dialing: %s", err)
}
defer conn.Close()
status, ping, err := CheckStatusOldConn(conn, host, port)
return status, ping, err
}
示例3: main
func main() {
//exit := make(chan bool)
ip := net.ParseIP("127.0.0.1")
port := 81
tcp_addr := net.TCPAddr{ip, port, ""}
udp_addr := net.UDPAddr{ip, port, ""}
fmt.Println(tcp_addr)
fmt.Println(udp_addr)
fmt.Println(tcp_addr.Network())
fmt.Println(udp_addr.Network())
}