Package net
import "net"
Package net provides a portable interface to Unix networks sockets, including TCP/IP, UDP, domain name resolution, and Unix domain sockets.
Package files
cgo_bsd.go cgo_linux.go cgo_stub.go cgo_unix.go dial.go dnsclient.go dnsclient_unix.go dnsconfig.go dnsmsg.go fd.go fd_linux.go file.go hosts.go interface.go interface_bsd.go interface_linux.go interface_stub.go ip.go iprawsock.go iprawsock_posix.go ipsock.go ipsock_posix.go lookup_unix.go net.go newpollserver.go parse.go pipe.go port.go sendfile_linux.go sendfile_stub.go sock.go sock_bsd.go sock_linux.go tcpsock.go tcpsock_posix.go udpsock.go udpsock_posix.go unixsock.go unixsock_posix.goConstants
IP address lengths (bytes).
const (
IPv4len = 4
IPv6len = 16
)
Variables
Well-known IPv4 addresses
var (
IPv4bcast = IPv4(255, 255, 255, 255) // broadcast
IPv4allsys = IPv4(224, 0, 0, 1) // all systems
IPv4allrouter = IPv4(224, 0, 0, 2) // all routers
IPv4zero = IPv4(0, 0, 0, 0) // all zeros
)
Well-known IPv6 addresses
var (
IPv6zero = IP{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
IPv6unspecified = IP{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
IPv6loopback = IP{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
IPv6interfacelocalallnodes = IP{0xff, 0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01}
IPv6linklocalallnodes = IP{0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01}
IPv6linklocalallrouters = IP{0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x02}
)
func InterfaceAddrs
func InterfaceAddrs() ([]Addr, os.Error)
InterfaceAddrs returns a list of the system's network interface addresses.
func Interfaces
func Interfaces() ([]Interface, os.Error)
Interfaces returns a list of the systems's network interfaces.
func JoinHostPort
func JoinHostPort(host, port string) string
JoinHostPort combines host and port into a network address of the form "host:port" or, if host contains a colon, "[host]:port".
func LookupAddr
func LookupAddr(addr string) (name []string, err os.Error)
LookupAddr performs a reverse lookup for the given address, returning a list of names mapping to that address.
func LookupCNAME
func LookupCNAME(name string) (cname string, err os.Error)
LookupCNAME returns the canonical DNS host for the given name. Callers that do not care about the canonical name can call LookupHost or LookupIP directly; both take care of resolving the canonical name as part of the lookup.
func LookupHost
func LookupHost(host string) (addrs []string, err os.Error)
LookupHost looks up the given host using the local resolver. It returns an array of that host's addresses.
func LookupIP
func LookupIP(host string) (addrs []IP, err os.Error)
LookupIP looks up host using the local resolver. It returns an array of that host's IPv4 and IPv6 addresses.
func LookupMX
func LookupMX(name string) (mx []*MX, err os.Error)
LookupMX returns the DNS MX records for the given domain name sorted by preference.
func LookupPort
func LookupPort(network, service string) (port int, err os.Error)
LookupPort looks up the port for the given network and service.
func LookupSRV
func LookupSRV(service, proto, name string) (cname string, addrs []*SRV, err os.Error)
LookupSRV tries to resolve an SRV query of the given service, protocol, and domain name, as specified in RFC 2782. In most cases the proto argument can be the same as the corresponding Addr.Network(). The returned records are sorted by priority and randomized by weight within a priority.
func SplitHostPort
func SplitHostPort(hostport string) (host, port string, err os.Error)
SplitHostPort splits a network address of the form "host:port" or "[host]:port" into host and port. The latter form must be used when host contains a colon.
type Addr
Addr represents a network end point address.
type Addr interface {
Network() string // name of the network
String() string // string form of address
}
type AddrError
type AddrError struct {
Error string
Addr string
}
func (*AddrError) String
func (e *AddrError) String() string
func (*AddrError) Temporary
func (e *AddrError) Temporary() bool
func (*AddrError) Timeout
func (e *AddrError) Timeout() bool
type Conn
Conn is a generic stream-oriented network connection.
type Conn interface {
// Read reads data from the connection.
// Read can be made to time out and return a net.Error with Timeout() == true
// after a fixed time limit; see SetTimeout and SetReadTimeout.
Read(b []byte) (n int, err os.Error)
// Write writes data to the connection.
// Write can be made to time out and return a net.Error with Timeout() == true
// after a fixed time limit; see SetTimeout and SetWriteTimeout.
Write(b []byte) (n int, err os.Error)
// Close closes the connection.
Close() os.Error
// LocalAddr returns the local network address.
LocalAddr() Addr
// RemoteAddr returns the remote network address.
RemoteAddr() Addr
// SetTimeout sets the read and write deadlines associated
// with the connection.
SetTimeout(nsec int64) os.Error
// SetReadTimeout sets the time (in nanoseconds) that
// Read will wait for data before returning an error with Timeout() == true.
// Setting nsec == 0 (the default) disables the deadline.
SetReadTimeout(nsec int64) os.Error
// SetWriteTimeout sets the time (in nanoseconds) that
// Write will wait to send its data before returning an error with Timeout() == true.
// Setting nsec == 0 (the default) disables the deadline.
// Even if write times out, it may return n > 0, indicating that
// some of the data was successfully written.
SetWriteTimeout(nsec int64) os.Error
}
func Dial
func Dial(net, addr string) (c Conn, err os.Error)
Dial connects to the address addr on the network net.
Known networks are "tcp", "tcp4" (IPv4-only), "tcp6" (IPv6-only), "udp", "udp4" (IPv4-only), "udp6" (IPv6-only), "ip", "ip4" (IPv4-only), "ip6" (IPv6-only), "unix" and "unixgram".
For IP networks, addresses have the form host:port. If host is a literal IPv6 address, it must be enclosed in square brackets. The functions JoinHostPort and SplitHostPort manipulate addresses in this form.
Examples:
Dial("tcp", "12.34.56.78:80")
Dial("tcp", "google.com:80")
Dial("tcp", "[de:ad:be:ef::ca:fe]:80")
func FileConn
func FileConn(f *os.File) (c Conn, err os.Error)
FileConn returns a copy of the network connection corresponding to the open file f. It is the caller's responsibility to close f when finished. Closing c does not affect f, and closing f does not affect c.
func Pipe
func Pipe() (Conn, Conn)
Pipe creates a synchronous, in-memory, full duplex network connection; both ends implement the Conn interface. Reads on one end are matched with writes on the other, copying data directly between the two; there is no internal buffering.
type DNSConfigError
type DNSConfigError struct {
Error os.Error
}
func (*DNSConfigError) String
func (e *DNSConfigError) String() string
func (*DNSConfigError) Temporary
func (e *DNSConfigError) Temporary() bool
func (*DNSConfigError) Timeout
func (e *DNSConfigError) Timeout() bool
type DNSError
DNSError represents a DNS lookup error.
type DNSError struct {
Error string // description of the error
Name string // name looked for
Server string // server used
IsTimeout bool
}
func (*DNSError) String
func (e *DNSError) String() string
func (*DNSError) Temporary
func (e *DNSError) Temporary() bool
func (*DNSError) Timeout
func (e *DNSError) Timeout() bool
type Error
An Error represents a network error.
type Error interface {
os.Error
Timeout() bool // Is the error a timeout?
Temporary() bool // Is the error temporary?
}
type Flags
type Flags uint
const (
FlagUp Flags = 1 << iota // interface is up
FlagBroadcast // interface supports broadcast access capability
FlagLoopback // interface is a loopback interface
FlagPointToPoint // interface belongs to a point-to-point link
FlagMulticast // interface supports multicast access capability
)
func (Flags) String
func (f Flags) String() string
type HardwareAddr
A HardwareAddr represents a physical hardware address.
type HardwareAddr []byte
func (HardwareAddr) String
func (a HardwareAddr) String() string
type IP
An IP is a single IP address, an array of bytes. Functions in this package accept either 4-byte (IP v4) or 16-byte (IP v6) arrays as input. Unless otherwise specified, functions in this package always return IP addresses in 16-byte form using the canonical embedding.
Note that in this documentation, referring to an IP address as an IPv4 address or an IPv6 address is a semantic property of the address, not just the length of the byte array: a 16-byte array can still be an IPv4 address.
type IP []byte
func IPv4
func IPv4(a, b, c, d byte) IP
IPv4 returns the IP address (in 16-byte form) of the IPv4 address a.b.c.d.
func ParseCIDR
func ParseCIDR(s string) (ip IP, mask IPMask, err os.Error)
ParseCIDR parses s as a CIDR notation IP address and mask, like "192.168.100.1/24", "2001:DB8::/48", as defined in RFC 4632 and RFC 4291.
func ParseIP
func ParseIP(s string) IP
ParseIP parses s as an IP address, returning the result. The string s can be in dotted decimal ("74.125.19.99") or IPv6 ("2001:4860:0:2001::68") form. If s is not a valid textual representation of an IP address, ParseIP returns nil.
func (IP) DefaultMask
func (ip IP) DefaultMask() IPMask
DefaultMask returns the default IP mask for the IP address ip. Only IPv4 addresses have default masks; DefaultMask returns nil if ip is not a valid IPv4 address.
func (IP) Equal
func (ip IP) Equal(x IP) bool
Equal returns true if ip and x are the same IP address. An IPv4 address and that same address in IPv6 form are considered to be equal.
func (IP) IsGlobalUnicast
func (ip IP) IsGlobalUnicast() bool
IsGlobalUnicast returns true if ip is a global unicast address.
func (IP) IsInterfaceLocalMulticast
func (ip IP) IsInterfaceLocalMulticast() bool
IsInterfaceLinkLocalMulticast returns true if ip is an interface-local multicast address.
func (IP) IsLinkLocalMulticast
func (ip IP) IsLinkLocalMulticast() bool
IsLinkLocalMulticast returns true if ip is a link-local multicast address.
func (IP) IsLinkLocalUnicast
func (ip IP) IsLinkLocalUnicast() bool
IsLinkLocalUnicast returns true if ip is a link-local unicast address.
func (IP) IsLoopback
func (ip IP) IsLoopback() bool
IsLoopback returns true if ip is a loopback address.
func (IP) IsMulticast
func (ip IP) IsMulticast() bool
IsMulticast returns true if ip is a multicast address.
func (IP) IsUnspecified
func (ip IP) IsUnspecified() bool
IsUnspecified returns true if ip is an unspecified address.
func (IP) Mask
func (ip IP) Mask(mask IPMask) IP
Mask returns the result of masking the IP address ip with mask.
func (IP) String
func (ip IP) String() string
String returns the string form of the IP address ip. If the address is an IPv4 address, the string representation is dotted decimal ("74.125.19.99"). Otherwise the representation is IPv6 ("2001:4860:0:2001::68").
func (IP) To16
func (ip IP) To16() IP
To16 converts the IP address ip to a 16-byte representation. If ip is not an IP address (it is the wrong length), To16 returns nil.
func (IP) To4
func (ip IP) To4() IP
To4 converts the IPv4 address ip to a 4-byte representation. If ip is not an IPv4 address, To4 returns nil.
type IPAddr
IPAddr represents the address of a IP end point.
type IPAddr struct {
IP IP
}
func ResolveIPAddr
func ResolveIPAddr(net, addr string) (*IPAddr, os.Error)
ResolveIPAddr parses addr as a IP address and resolves domain names to numeric addresses on the network net, which must be "ip", "ip4" or "ip6". A literal IPv6 host address must be enclosed in square brackets, as in "[::]".
func (*IPAddr) Network
func (a *IPAddr) Network() string
Network returns the address's network name, "ip".
func (*IPAddr) String
func (a *IPAddr) String() string
type IPConn
IPConn is the implementation of the Conn and PacketConn interfaces for IP network connections.
type IPConn struct {
// contains filtered or unexported fields
}
func DialIP
func DialIP(netProto string, laddr, raddr *IPAddr) (c *IPConn, err os.Error)
DialIP connects to the remote address raddr on the network net, which must be "ip", "ip4", or "ip6".
func ListenIP
func ListenIP(netProto string, laddr *IPAddr) (c *IPConn, err os.Error)
ListenIP listens for incoming IP packets addressed to the local address laddr. The returned connection c's ReadFrom and WriteTo methods can be used to receive and send IP packets with per-packet addressing.
func (*IPConn) BindToDevice
func (c *IPConn) BindToDevice(device string) os.Error
BindToDevice binds an IPConn to a network interface.
func (*IPConn) Close
func (c *IPConn) Close() os.Error
Close closes the IP connection.
func (*IPConn) LocalAddr
func (c *IPConn) LocalAddr() Addr
LocalAddr returns the local network address.
func (*IPConn) Read
func (c *IPConn) Read(b []byte) (n int, err os.Error)
Read implements the net.Conn Read method.
func (*IPConn) ReadFrom
func (c *IPConn) ReadFrom(b []byte) (n int, addr Addr, err os.Error)
ReadFrom implements the net.PacketConn ReadFrom method.
func (*IPConn) ReadFromIP
func (c *IPConn) ReadFromIP(b []byte) (n int, addr *IPAddr, err os.Error)
ReadFromIP reads a IP packet from c, copying the payload into b. It returns the number of bytes copied into b and the return address that was on the packet.
ReadFromIP can be made to time out and return an error with Timeout() == true after a fixed time limit; see SetTimeout and SetReadTimeout.
func (*IPConn) RemoteAddr
func (c *IPConn) RemoteAddr() Addr
RemoteAddr returns the remote network address, a *IPAddr.
func (*IPConn) SetReadBuffer
func (c *IPConn) SetReadBuffer(bytes int) os.Error
SetReadBuffer sets the size of the operating system's receive buffer associated with the connection.
func (*IPConn) SetReadTimeout
func (c *IPConn) SetReadTimeout(nsec int64) os.Error
SetReadTimeout implements the net.Conn SetReadTimeout method.
func (*IPConn) SetTimeout
func (c *IPConn) SetTimeout(nsec int64) os.Error
SetTimeout implements the net.Conn SetTimeout method.
func (*IPConn) SetWriteBuffer
func (c *IPConn) SetWriteBuffer(bytes int) os.Error
SetWriteBuffer sets the size of the operating system's transmit buffer associated with the connection.
func (*IPConn) SetWriteTimeout
func (c *IPConn) SetWriteTimeout(nsec int64) os.Error
SetWriteTimeout implements the net.Conn SetWriteTimeout method.
func (*IPConn) Write
func (c *IPConn) Write(b []byte) (n int, err os.Error)
Write implements the net.Conn Write method.
func (*IPConn) WriteTo
func (c *IPConn) WriteTo(b []byte, addr Addr) (n int, err os.Error)
WriteTo implements the net.PacketConn WriteTo method.
func (*IPConn) WriteToIP
func (c *IPConn) WriteToIP(b []byte, addr *IPAddr) (n int, err os.Error)
WriteToIP writes a IP packet to addr via c, copying the payload from b.
WriteToIP can be made to time out and return an error with Timeout() == true after a fixed time limit; see SetTimeout and SetWriteTimeout. On packet-oriented connections, write timeouts are rare.
type IPMask
An IP mask is an IP address.
type IPMask []byte
func IPv4Mask
func IPv4Mask(a, b, c, d byte) IPMask
IPv4Mask returns the IP mask (in 16-byte form) of the IPv4 mask a.b.c.d.
func (IPMask) String
func (mask IPMask) String() string
String returns the string representation of mask. If the mask is in the canonical form--ones followed by zeros--the string representation is just the decimal number of ones. If the mask is in a non-canonical form, it is formatted as an IP address.
type Interface
Interface represents a mapping between network interface name and index. It also represents network interface facility information.
type Interface struct {
Index int // positive integer that starts at one, zero is never used
MTU int // maximum transmission unit
Name string // e.g., "en0", "lo0", "eth0.100"
HardwareAddr HardwareAddr // IEEE MAC-48, EUI-48 and EUI-64 form
Flags Flags // e.g., FlagUp, FlagLoopback, FlagMulticast
}
func InterfaceByIndex
func InterfaceByIndex(index int) (*Interface, os.Error)
InterfaceByIndex returns the interface specified by index.
func InterfaceByName
func InterfaceByName(name string) (*Interface, os.Error)
InterfaceByName returns the interface specified by name.
func (*Interface) Addrs
func (ifi *Interface) Addrs() ([]Addr, os.Error)
Addrs returns interface addresses for a specific interface.
func (*Interface) MulticastAddrs
func (ifi *Interface) MulticastAddrs() ([]Addr, os.Error)
MulticastAddrs returns multicast, joined group addresses for a specific interface.
type InvalidAddrError
type InvalidAddrError string
func (InvalidAddrError) String
func (e InvalidAddrError) String() string
func (InvalidAddrError) Temporary
func (e InvalidAddrError) Temporary() bool
func (InvalidAddrError) Timeout
func (e InvalidAddrError) Timeout() bool
type InvalidConnError
type InvalidConnError struct{}
func (*InvalidConnError) String
func (e *InvalidConnError) String() string
func (*InvalidConnError) Temporary
func (e *InvalidConnError) Temporary() bool
func (*InvalidConnError) Timeout
func (e *InvalidConnError) Timeout() bool
type Listener
A Listener is a generic network listener for stream-oriented protocols.
type Listener interface {
// Accept waits for and returns the next connection to the listener.
Accept() (c Conn, err os.Error)
// Close closes the listener.
Close() os.Error
// Addr returns the listener's network address.
Addr() Addr
}
func FileListener
func FileListener(f *os.File) (l Listener, err os.Error)
FileListener returns a copy of the network listener corresponding to the open file f. It is the caller's responsibility to close l when finished. Closing c does not affect l, and closing l does not affect c.
func Listen
func Listen(net, laddr string) (l Listener, err os.Error)
Listen announces on the local network address laddr. The network string net must be a stream-oriented network: "tcp", "tcp4", "tcp6", or "unix", or "unixpacket".
type MX
An MX represents a single DNS MX record.
type MX struct {
Host string
Pref uint16
}
type OpError
type OpError struct {
Op string
Net string
Addr Addr
Error os.Error
}
func (*OpError) String
func (e *OpError) String() string
func (*OpError) Temporary
func (e *OpError) Temporary() bool
func (*OpError) Timeout
func (e *OpError) Timeout() bool
type PacketConn
PacketConn is a generic packet-oriented network connection.
type PacketConn interface {
// ReadFrom reads a packet from the connection,
// copying the payload into b. It returns the number of
// bytes copied into b and the return address that
// was on the packet.
// ReadFrom can be made to time out and return
// an error with Timeout() == true after a fixed time limit;
// see SetTimeout and SetReadTimeout.
ReadFrom(b []byte) (n int, addr Addr, err os.Error)
// WriteTo writes a packet with payload b to addr.
// WriteTo can be made to time out and return
// an error with Timeout() == true after a fixed time limit;
// see SetTimeout and SetWriteTimeout.
// On packet-oriented connections, write timeouts are rare.
WriteTo(b []byte, addr Addr) (n int, err os.Error)
// Close closes the connection.
Close() os.Error
// LocalAddr returns the local network address.
LocalAddr() Addr
// SetTimeout sets the read and write deadlines associated
// with the connection.
SetTimeout(nsec int64) os.Error
// SetReadTimeout sets the time (in nanoseconds) that
// Read will wait for data before returning an error with Timeout() == true.
// Setting nsec == 0 (the default) disables the deadline.
SetReadTimeout(nsec int64) os.Error
// SetWriteTimeout sets the time (in nanoseconds) that
// Write will wait to send its data before returning an error with Timeout() == true.
// Setting nsec == 0 (the default) disables the deadline.
// Even if write times out, it may return n > 0, indicating that
// some of the data was successfully written.
SetWriteTimeout(nsec int64) os.Error
}
func FilePacketConn
func FilePacketConn(f *os.File) (c PacketConn, err os.Error)
FilePacketConn returns a copy of the packet network connection corresponding to the open file f. It is the caller's responsibility to close f when finished. Closing c does not affect f, and closing f does not affect c.
func ListenPacket
func ListenPacket(net, laddr string) (c PacketConn, err os.Error)
ListenPacket announces on the local network address laddr. The network string net must be a packet-oriented network: "udp", "udp4", "udp6", or "unixgram".
type ParseError
A ParseError represents a malformed text string and the type of string that was expected.
type ParseError struct {
Type string
Text string
}
func (*ParseError) String
func (e *ParseError) String() string
type SRV
An SRV represents a single DNS SRV record.
type SRV struct {
Target string
Port uint16
Priority uint16
Weight uint16
}
type TCPAddr
TCPAddr represents the address of a TCP end point.
type TCPAddr struct {
IP IP
Port int
}
func ResolveTCPAddr
func ResolveTCPAddr(net, addr string) (*TCPAddr, os.Error)
ResolveTCPAddr parses addr as a TCP address of the form host:port and resolves domain names or port names to numeric addresses on the network net, which must be "tcp", "tcp4" or "tcp6". A literal IPv6 host address must be enclosed in square brackets, as in "[::]:80".
func (*TCPAddr) Network
func (a *TCPAddr) Network() string
Network returns the address's network name, "tcp".
func (*TCPAddr) String
func (a *TCPAddr) String() string
type TCPConn
TCPConn is an implementation of the Conn interface for TCP network connections.
type TCPConn struct {
// contains filtered or unexported fields
}
func DialTCP
func DialTCP(net string, laddr, raddr *TCPAddr) (c *TCPConn, err os.Error)
DialTCP connects to the remote address raddr on the network net, which must be "tcp", "tcp4", or "tcp6". If laddr is not nil, it is used as the local address for the connection.
func (*TCPConn) Close
func (c *TCPConn) Close() os.Error
Close closes the TCP connection.
func (*TCPConn) File
func (c *TCPConn) File() (f *os.File, err os.Error)
File returns a copy of the underlying os.File, set to blocking mode. It is the caller's responsibility to close f when finished. Closing c does not affect f, and closing f does not affect c.
func (*TCPConn) LocalAddr
func (c *TCPConn) LocalAddr() Addr
LocalAddr returns the local network address, a *TCPAddr.
func (*TCPConn) Read
func (c *TCPConn) Read(b []byte) (n int, err os.Error)
Read implements the net.Conn Read method.
func (*TCPConn) ReadFrom
func (c *TCPConn) ReadFrom(r io.Reader) (int64, os.Error)
ReadFrom implements the io.ReaderFrom ReadFrom method.
func (*TCPConn) RemoteAddr
func (c *TCPConn) RemoteAddr() Addr
RemoteAddr returns the remote network address, a *TCPAddr.
func (*TCPConn) SetKeepAlive
func (c *TCPConn) SetKeepAlive(keepalive bool) os.Error
SetKeepAlive sets whether the operating system should send keepalive messages on the connection.
func (*TCPConn) SetLinger
func (c *TCPConn) SetLinger(sec int) os.Error
SetLinger sets the behavior of Close() on a connection which still has data waiting to be sent or to be acknowledged.
If sec < 0 (the default), Close returns immediately and the operating system finishes sending the data in the background.
If sec == 0, Close returns immediately and the operating system discards any unsent or unacknowledged data.
If sec > 0, Close blocks for at most sec seconds waiting for data to be sent and acknowledged.
func (*TCPConn) SetNoDelay
func (c *TCPConn) SetNoDelay(noDelay bool) os.Error
SetNoDelay controls whether the operating system should delay packet transmission in hopes of sending fewer packets (Nagle's algorithm). The default is true (no delay), meaning that data is sent as soon as possible after a Write.
func (*TCPConn) SetReadBuffer
func (c *TCPConn) SetReadBuffer(bytes int) os.Error
SetReadBuffer sets the size of the operating system's receive buffer associated with the connection.
func (*TCPConn) SetReadTimeout
func (c *TCPConn) SetReadTimeout(nsec int64) os.Error
SetReadTimeout implements the net.Conn SetReadTimeout method.
func (*TCPConn) SetTimeout
func (c *TCPConn) SetTimeout(nsec int64) os.Error
SetTimeout implements the net.Conn SetTimeout method.
func (*TCPConn) SetWriteBuffer
func (c *TCPConn) SetWriteBuffer(bytes int) os.Error
SetWriteBuffer sets the size of the operating system's transmit buffer associated with the connection.
func (*TCPConn) SetWriteTimeout
func (c *TCPConn) SetWriteTimeout(nsec int64) os.Error
SetWriteTimeout implements the net.Conn SetWriteTimeout method.
func (*TCPConn) Write
func (c *TCPConn) Write(b []byte) (n int, err os.Error)
Write implements the net.Conn Write method.
type TCPListener
TCPListener is a TCP network listener. Clients should typically use variables of type Listener instead of assuming TCP.
type TCPListener struct {
// contains filtered or unexported fields
}
func ListenTCP
func ListenTCP(net string, laddr *TCPAddr) (l *TCPListener, err os.Error)
ListenTCP announces on the TCP address laddr and returns a TCP listener. Net must be "tcp", "tcp4", or "tcp6". If laddr has a port of 0, it means to listen on some available port. The caller can use l.Addr() to retrieve the chosen address.
func (*TCPListener) Accept
func (l *TCPListener) Accept() (c Conn, err os.Error)
Accept implements the Accept method in the Listener interface; it waits for the next call and returns a generic Conn.
func (*TCPListener) AcceptTCP
func (l *TCPListener) AcceptTCP() (c *TCPConn, err os.Error)
AcceptTCP accepts the next incoming call and returns the new connection and the remote address.
func (*TCPListener) Addr
func (l *TCPListener) Addr() Addr
Addr returns the listener's network address, a *TCPAddr.
func (*TCPListener) Close
func (l *TCPListener) Close() os.Error
Close stops listening on the TCP address. Already Accepted connections are not closed.
func (*TCPListener) File
func (l *TCPListener) File() (f *os.File, err os.Error)
File returns a copy of the underlying os.File, set to blocking mode. It is the caller's responsibility to close f when finished. Closing c does not affect f, and closing f does not affect c.
func (*TCPListener) SetTimeout
func (l *TCPListener) SetTimeout(nsec int64) os.Error
SetTimeout sets the deadline associated with the listener
type UDPAddr
UDPAddr represents the address of a UDP end point.
type UDPAddr struct {
IP IP
Port int
}
func ResolveUDPAddr
func ResolveUDPAddr(net, addr string) (*UDPAddr, os.Error)
ResolveUDPAddr parses addr as a UDP address of the form host:port and resolves domain names or port names to numeric addresses on the network net, which must be "udp", "udp4" or "udp6". A literal IPv6 host address must be enclosed in square brackets, as in "[::]:80".
func (*UDPAddr) Network
func (a *UDPAddr) Network() string
Network returns the address's network name, "udp".
func (*UDPAddr) String
func (a *UDPAddr) String() string
type UDPConn
UDPConn is the implementation of the Conn and PacketConn interfaces for UDP network connections.
type UDPConn struct {
// contains filtered or unexported fields
}
func DialUDP
func DialUDP(net string, laddr, raddr *UDPAddr) (c *UDPConn, err os.Error)
DialUDP connects to the remote address raddr on the network net, which must be "udp", "udp4", or "udp6". If laddr is not nil, it is used as the local address for the connection.
func ListenUDP
func ListenUDP(net string, laddr *UDPAddr) (c *UDPConn, err os.Error)
ListenUDP listens for incoming UDP packets addressed to the local address laddr. The returned connection c's ReadFrom and WriteTo methods can be used to receive and send UDP packets with per-packet addressing.
func ListenUnixgram
func ListenUnixgram(net string, laddr *UnixAddr) (c *UDPConn, err os.Error)
ListenUnixgram listens for incoming Unix datagram packets addressed to the local address laddr. The returned connection c's ReadFrom and WriteTo methods can be used to receive and send UDP packets with per-packet addressing. The network net must be "unixgram".
func (*UDPConn) BindToDevice
func (c *UDPConn) BindToDevice(device string) os.Error
BindToDevice binds a UDPConn to a network interface.
func (*UDPConn) Close
func (c *UDPConn) Close() os.Error
Close closes the UDP connection.
func (*UDPConn) File
func (c *UDPConn) File() (f *os.File, err os.Error)
File returns a copy of the underlying os.File, set to blocking mode. It is the caller's responsibility to close f when finished. Closing c does not affect f, and closing f does not affect c.
func (*UDPConn) JoinGroup
func (c *UDPConn) JoinGroup(addr IP) os.Error
JoinGroup joins the IPv4 multicast group named by addr. The UDPConn must use the "udp4" network.
func (*UDPConn) LeaveGroup
func (c *UDPConn) LeaveGroup(addr IP) os.Error
LeaveGroup exits the IPv4 multicast group named by addr.
func (*UDPConn) LocalAddr
func (c *UDPConn) LocalAddr() Addr
LocalAddr returns the local network address.
func (*UDPConn) Read
func (c *UDPConn) Read(b []byte) (n int, err os.Error)
Read implements the net.Conn Read method.
func (*UDPConn) ReadFrom
func (c *UDPConn) ReadFrom(b []byte) (n int, addr Addr, err os.Error)
ReadFrom implements the net.PacketConn ReadFrom method.
func (*UDPConn) ReadFromUDP
func (c *UDPConn) ReadFromUDP(b []byte) (n int, addr *UDPAddr, err os.Error)
ReadFromUDP reads a UDP packet from c, copying the payload into b. It returns the number of bytes copied into b and the return address that was on the packet.
ReadFromUDP can be made to time out and return an error with Timeout() == true after a fixed time limit; see SetTimeout and SetReadTimeout.
func (*UDPConn) RemoteAddr
func (c *UDPConn) RemoteAddr() Addr
RemoteAddr returns the remote network address, a *UDPAddr.
func (*UDPConn) SetReadBuffer
func (c *UDPConn) SetReadBuffer(bytes int) os.Error
SetReadBuffer sets the size of the operating system's receive buffer associated with the connection.
func (*UDPConn) SetReadTimeout
func (c *UDPConn) SetReadTimeout(nsec int64) os.Error
SetReadTimeout implements the net.Conn SetReadTimeout method.
func (*UDPConn) SetTimeout
func (c *UDPConn) SetTimeout(nsec int64) os.Error
SetTimeout implements the net.Conn SetTimeout method.
func (*UDPConn) SetWriteBuffer
func (c *UDPConn) SetWriteBuffer(bytes int) os.Error
SetWriteBuffer sets the size of the operating system's transmit buffer associated with the connection.
func (*UDPConn) SetWriteTimeout
func (c *UDPConn) SetWriteTimeout(nsec int64) os.Error
SetWriteTimeout implements the net.Conn SetWriteTimeout method.
func (*UDPConn) Write
func (c *UDPConn) Write(b []byte) (n int, err os.Error)
Write implements the net.Conn Write method.
func (*UDPConn) WriteTo
func (c *UDPConn) WriteTo(b []byte, addr Addr) (n int, err os.Error)
WriteTo implements the net.PacketConn WriteTo method.
func (*UDPConn) WriteToUDP
func (c *UDPConn) WriteToUDP(b []byte, addr *UDPAddr) (n int, err os.Error)
WriteToUDP writes a UDP packet to addr via c, copying the payload from b.
WriteToUDP can be made to time out and return an error with Timeout() == true after a fixed time limit; see SetTimeout and SetWriteTimeout. On packet-oriented connections, write timeouts are rare.
type UnixAddr
UnixAddr represents the address of a Unix domain socket end point.
type UnixAddr struct {
Name string
Net string
}
func ResolveUnixAddr
func ResolveUnixAddr(net, addr string) (*UnixAddr, os.Error)
ResolveUnixAddr parses addr as a Unix domain socket address. The string net gives the network name, "unix", "unixgram" or "unixpacket".
func (*UnixAddr) Network
func (a *UnixAddr) Network() string
Network returns the address's network name, "unix" or "unixgram".
func (*UnixAddr) String
func (a *UnixAddr) String() string
type UnixConn
UnixConn is an implementation of the Conn interface for connections to Unix domain sockets.
type UnixConn struct {
// contains filtered or unexported fields
}
func DialUnix
func DialUnix(net string, laddr, raddr *UnixAddr) (c *UnixConn, err os.Error)
DialUnix connects to the remote address raddr on the network net, which must be "unix" or "unixgram". If laddr is not nil, it is used as the local address for the connection.
func (*UnixConn) Close
func (c *UnixConn) Close() os.Error
Close closes the Unix domain connection.
func (*UnixConn) File
func (c *UnixConn) File() (f *os.File, err os.Error)
File returns a copy of the underlying os.File, set to blocking mode. It is the caller's responsibility to close f when finished. Closing c does not affect f, and closing f does not affect c.
func (*UnixConn) LocalAddr
func (c *UnixConn) LocalAddr() Addr
LocalAddr returns the local network address, a *UnixAddr. Unlike in other protocols, LocalAddr is usually nil for dialed connections.
func (*UnixConn) Read
func (c *UnixConn) Read(b []byte) (n int, err os.Error)
Read implements the net.Conn Read method.
func (*UnixConn) ReadFrom
func (c *UnixConn) ReadFrom(b []byte) (n int, addr Addr, err os.Error)
ReadFrom implements the net.PacketConn ReadFrom method.
func (*UnixConn) ReadFromUnix
func (c *UnixConn) ReadFromUnix(b []byte) (n int, addr *UnixAddr, err os.Error)
ReadFromUnix reads a packet from c, copying the payload into b. It returns the number of bytes copied into b and the return address that was on the packet.
ReadFromUnix can be made to time out and return an error with Timeout() == true after a fixed time limit; see SetTimeout and SetReadTimeout.
func (*UnixConn) ReadMsgUnix
func (c *UnixConn) ReadMsgUnix(b, oob []byte) (n, oobn, flags int, addr *UnixAddr, err os.Error)
func (*UnixConn) RemoteAddr
func (c *UnixConn) RemoteAddr() Addr
RemoteAddr returns the remote network address, a *UnixAddr. Unlike in other protocols, RemoteAddr is usually nil for connections accepted by a listener.
func (*UnixConn) SetReadBuffer
func (c *UnixConn) SetReadBuffer(bytes int) os.Error
SetReadBuffer sets the size of the operating system's receive buffer associated with the connection.
func (*UnixConn) SetReadTimeout
func (c *UnixConn) SetReadTimeout(nsec int64) os.Error
SetReadTimeout implements the net.Conn SetReadTimeout method.
func (*UnixConn) SetTimeout
func (c *UnixConn) SetTimeout(nsec int64) os.Error
SetTimeout implements the net.Conn SetTimeout method.
func (*UnixConn) SetWriteBuffer
func (c *UnixConn) SetWriteBuffer(bytes int) os.Error
SetWriteBuffer sets the size of the operating system's transmit buffer associated with the connection.
func (*UnixConn) SetWriteTimeout
func (c *UnixConn) SetWriteTimeout(nsec int64) os.Error
SetWriteTimeout implements the net.Conn SetWriteTimeout method.
func (*UnixConn) Write
func (c *UnixConn) Write(b []byte) (n int, err os.Error)
Write implements the net.Conn Write method.
func (*UnixConn) WriteMsgUnix
func (c *UnixConn) WriteMsgUnix(b, oob []byte, addr *UnixAddr) (n, oobn int, err os.Error)
func (*UnixConn) WriteTo
func (c *UnixConn) WriteTo(b []byte, addr Addr) (n int, err os.Error)
WriteTo implements the net.PacketConn WriteTo method.
func (*UnixConn) WriteToUnix
func (c *UnixConn) WriteToUnix(b []byte, addr *UnixAddr) (n int, err os.Error)
WriteToUnix writes a packet to addr via c, copying the payload from b.
WriteToUnix can be made to time out and return an error with Timeout() == true after a fixed time limit; see SetTimeout and SetWriteTimeout. On packet-oriented connections, write timeouts are rare.
type UnixListener
UnixListener is a Unix domain socket listener. Clients should typically use variables of type Listener instead of assuming Unix domain sockets.
type UnixListener struct {
// contains filtered or unexported fields
}
func ListenUnix
func ListenUnix(net string, laddr *UnixAddr) (l *UnixListener, err os.Error)
ListenUnix announces on the Unix domain socket laddr and returns a Unix listener. Net must be "unix" (stream sockets).
func (*UnixListener) Accept
func (l *UnixListener) Accept() (c Conn, err os.Error)
Accept implements the Accept method in the Listener interface; it waits for the next call and returns a generic Conn.
func (*UnixListener) AcceptUnix
func (l *UnixListener) AcceptUnix() (c *UnixConn, err os.Error)
AcceptUnix accepts the next incoming call and returns the new connection and the remote address.
func (*UnixListener) Addr
func (l *UnixListener) Addr() Addr
Addr returns the listener's network address.
func (*UnixListener) Close
func (l *UnixListener) Close() os.Error
Close stops listening on the Unix address. Already accepted connections are not closed.
func (*UnixListener) File
func (l *UnixListener) File() (f *os.File, err os.Error)
File returns a copy of the underlying os.File, set to blocking mode. It is the caller's responsibility to close f when finished. Closing c does not affect f, and closing f does not affect c.
func (*UnixListener) SetTimeout
func (l *UnixListener) SetTimeout(nsec int64) (err os.Error)
SetTimeout sets the deadline associated wuth the listener
type UnknownNetworkError
type UnknownNetworkError string
func (UnknownNetworkError) String
func (e UnknownNetworkError) String() string
func (UnknownNetworkError) Temporary
func (e UnknownNetworkError) Temporary() bool
func (UnknownNetworkError) Timeout
func (e UnknownNetworkError) Timeout() bool
type UnknownSocketError
type UnknownSocketError struct {
// contains filtered or unexported fields
}
func (*UnknownSocketError) String
func (e *UnknownSocketError) String() string
Need more packages? The Package Dashboard provides a list of goinstallable packages.
Subdirectories
| Name | Synopsis | |
|---|---|---|
| .. | ||
| dict | Package dict implements the Dictionary Server Protocol as defined in RFC 2229. | |
| textproto | Package textproto implements generic support for text-based request/response protocols in the style of HTTP, NNTP, and SMTP. The package provides: Error, which represents a numeric error response from a server. |