本文整理匯總了Golang中net.UDPAddr.Zone方法的典型用法代碼示例。如果您正苦於以下問題:Golang UDPAddr.Zone方法的具體用法?Golang UDPAddr.Zone怎麽用?Golang UDPAddr.Zone使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.UDPAddr
的用法示例。
在下文中一共展示了UDPAddr.Zone方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: OpenPort
/*------------------------------------------------------------------------
* int OpenPort(ttp_session_t *session);
*
* Creates a new UDP socket for transmitting the file data associated
* with our pending transfer and receives the destination port number
* from the client. Returns 0 on success and non-zero on failure.
*------------------------------------------------------------------------*/
func (session *Session) OpenPort() error {
/* create the address structure */
var udp_address net.UDPAddr
if session.parameter.client == "" {
address := session.client_fd.RemoteAddr()
addr := address.(*net.TCPAddr)
udp_address.IP = addr.IP
udp_address.Zone = addr.Zone
} else {
addr, err := net.ResolveIPAddr("ip", session.parameter.client)
if err != nil {
return err
}
if addr.Network() == "ipv6" {
session.parameter.ipv6 = true
}
udp_address.IP = addr.IP
udp_address.Zone = addr.Zone
}
if udp_address.String() == "" {
return nil
}
/* read in the port number from the client */
buf := make([]byte, 2)
_, err := session.client_fd.Read(buf)
if err != nil {
return err
}
x := binary.BigEndian.Uint16(buf)
udp_address.Port = int(x)
if session.parameter.verbose {
Warn("Sending to client port ", x)
}
fd, err := createUdpSocket(session.parameter, &udp_address)
if err != nil {
return Warn("Could not create UDP socket", err)
}
session.transfer.udp_fd = fd
session.transfer.udp_address = &udp_address
return nil
}