外观
inet
原文: https://finproducts.atlassian.net/wiki/spaces/JIDD3/pages/34793455743/FIN+5.3.1+inet 中文整理基于 FIN 5.3.1
导读: IpAddr 模型既能表示 IPv4 和 IPv6 数字地址,也能提供 DNS 主机名解析。
以下为 API 参考,保留英文以便对照源码;目录已列出(英文标题便于检索);概述已尽量中译。
目录(导读)
- classes
- errs
- Slot Details
- bytes
- equals
- hash
- hostname
- isIPv4
- isIPv6
- isLoopback
- isSiteLocal
- local
- make
- makeAll
- makeBytes
- numeric
- toNative
- toStr
- addrs
- broadcastAddrs
- dis
- findByAddr
- findByName
- hardwareAddr
- isPointToPoint
- isUp
- list
- mtu
- name
- prefixSize
- supportsMulticast
- interface
- joinGroup
- leaveGroup
- loopbackMode
- timeToLive
- acceptTimeout
- broadcast
- connectTimeout
- copy
- cur
- inBufferSize
- keepAlive
- keystore
- linger
- noDelay
- outBufferSize
- receiveBufferSize
- receiveTimeout
- reuseAddr
- sendBufferSize
- setCur
- setTimeouts
- trafficClass
- truststore
- copyFrom
- accept
- bind
- close
- config
- isBound
- isClosed
- localAddr
- localPort
- options
- connect
- in
- isConnected
- out
- remoteAddr
- remotePort
- shutdownIn
- shutdownOut
- upgradeTls
- addr
- data
- port
- disconnect
- receive
- send
概述(中译)
const class IpAddr : Obj
IpAddr 模型既能表示 IPv4 和 IPv6 数字地址,也能提供 DNS 主机名解析。
构造函数
方法
插槽详情
API 正文(英文)
bytes
Buf bytes()
Get the raw bytes of this address as a Buf of 4 or 16 bytes for IPv4 or IPv6 respectively. The buf position is zero.
equals
virtual override Bool equals(Obj? obj)
Equality is based on equivalent address bytes.
hash
virtual override Int hash()
Hash code is based the address bytes.
hostname
Str hostname()
Return the hostname of this address. If a hostname was specified in make, then that string is used. Otherwise this method will perform a reverse DNS lookup potentially blocking the calling thread. If the address cannot be mapped to a hostname, then return the address in its numeric format.
isIPv4
Bool isIPv4()
Is this a 32 bit (four byte) IP version 4 address.
isIPv6
Bool isIPv6()
Is this a 128 bit (sixteen byte) IP version 6 address.
isLoopback
Bool isLoopback()
Is this a loopback address.
isSiteLocal
Bool isSiteLocal()
Is this a site local address.
local
static IpAddr local()
Return the IpAddr for the local machine.
make
static new make(Str s)
Parse an IP address formated as an IPv4 numeric address, IPv6 numeric address, or a DNS hostname. If a hostname if provided, then it is resolved to an IP address potentially blocking the calling thread. If the address is invalid or a hostname cannot be resolved then UnknownHostErr is thrown.
Examples:
IpAddr("169.200.3.103")
IpAddr("1080:0:0:0:8:800:200C:417A")
IpAddr("1080::8:800:200C:417A")
IpAddr("::ffff:129.144.52.38")
IpAddr("somehost")
IpAddr("www.acme.com")makeAll
static IpAddr[] makeAll(Str s)
Resolve a hostname to all of its configured IP addresses. If a numeric IPv4 or IPv6 address is specified then a list of one IpAddr is returned. If a hostname if provided, then it is resolved to all its configured IP addresses potentially blocking the calling thread. If the address is invalid or a hostname cannot be resolved then UnknownHostErr is thrown.
makeBytes
static IpAddr makeBytes(Buf bytes)
Make an IpAddr for the specified raw bytes. The size of the byte buffer must be 4 for IPv4 or 16 for IPv6, otherwise ArgErr is thrown. The bytes must be a memory backed buffer.
numeric
Str numeric()
Get this address as a Str in its numeric notation. For IPv4 this is four decimal digits separated by dots. For IPv6 this is eight hexadecimal digits separated by colons.
toNative
Obj toNative()
To the native platform representation:
- Java: returns
java.net.InetAddress - .NET: returns
System.Net.IPAddress
toStr
virtual override Str toStr()
Return the exact string passed to the constructor.
IpInterface
const class IpInterface : Obj
Network interface which models name and IP addresses assigned
Methods
| addrs | Return list of IP addresses bound to this interface |
| broadcastAddrs | Return list of all broadcast IP addresses bound to this interface |
| dis | Display name of the interface |
| equals | Equality is based on interface name and addresses |
| findByAddr | Find the interface bound to the given IP address. |
| findByName | Find the interface by its name. |
| hardwareAddr | Media Access Control (MAC) or physical address for this interface return null if address does not exist. |
| hash | Hash code is based on interface name and addresses |
| isLoopback | Return true if a loopback interface |
| isPointToPoint | Return true if point to point interface (PPP through modem) |
| isUp | Return true if interface is up and running |
| list | List the interfaces on this machine |
| mtu | Maximum transmission unit of interface |
| name | Name of the interface |
| prefixSize | Returns the network prefix length in bits for given address. |
| supportsMulticast | Return true if interface supports multicast |
| toStr | Return string representation. |
Slot Details
addrs
IpAddr[] addrs()
Return list of IP addresses bound to this interface
broadcastAddrs
IpAddr[] broadcastAddrs()
Return list of all broadcast IP addresses bound to this interface
dis
Str dis()
Display name of the interface
equals
virtual override Bool equals(Obj? obj)
Equality is based on interface name and addresses
findByAddr
static IpInterface? findByAddr(IpAddr addr, Bool checked := true)
Find the interface bound to the given IP address. If multiple interfaces are bound to the address it is undefined which one is returned. If no interfaces are bound then return null or raise UnresolvedErr based on checked flag.
findByName
static IpInterface? findByName(Str name, Bool checked := true)
Find the interface by its name. If the interface is not found then return null or raise UnresolvedErr based on checked flag.
hardwareAddr
Buf? hardwareAddr()
Media Access Control (MAC) or physical address for this interface return null if address does not exist.
hash
virtual override Int hash()
Hash code is based on interface name and addresses
isLoopback
Bool isLoopback()
Return true if a loopback interface
isPointToPoint
Bool isPointToPoint()
Return true if point to point interface (PPP through modem)
isUp
Bool isUp()
Return true if interface is up and running
list
static IpInterface[] list()
List the interfaces on this machine
mtu
Int mtu()
Maximum transmission unit of interface
name
Str name()
Name of the interface
prefixSize
Int prefixSize(IpAddr addr)
Returns the network prefix length in bits for given address. This is also known as the subnet mask in the context of IPv4 addresses. Typical IPv4 values would be 8 (255.0.0.0), 16 (255.255.0.0) or 24 (255.255.255.0).
supportsMulticast
Bool supportsMulticast()
Return true if interface supports multicast
toStr
virtual override Str toStr()
Return string representation.
MulticastSocket
class MulticastSocket : UdpSocket
MulticastSocket extends UdpSocket to provide multicast capabilities.
Constructors
| make | Make a new unbound multicast UDP socket. |
Fields
| interface | Default network interface for outgoing datagrams on this socket |
| loopbackMode | True to enable outgoing packets to be received by the local socket. |
| timeToLive | Default time to live for packets send on this socket. |
Methods
| joinGroup | Join a multicast group. |
| leaveGroup | Leave a multicast group. |
Slot Details
interface
IpInterface interface
Default network interface for outgoing datagrams on this socket
joinGroup
This joinGroup(IpAddr addr, Int? port := null, IpInterface? interface := null)
Join a multicast group. If interface parameter is null, then interface field is used. Return this.
leaveGroup
This leaveGroup(IpAddr addr, Int? port := null, IpInterface? interface := null)
Leave a multicast group. If interface parameter is null, then interface field is used. Return this.
loopbackMode
Bool loopbackMode
True to enable outgoing packets to be received by the local socket.
make
new make(SocketConfig config := SocketConfig.cur())
Make a new unbound multicast UDP socket.
timeToLive
Int timeToLive
Default time to live for packets send on this socket. Value must be between 0 and 255. TTL of zero is only delivered locally.
SocketConfig
const class SocketConfig : Obj
Configuration options for TCP and UDP sockets. All socket types accept a socket configuration which will be used to configure the socket when it is created.
A system-wide default socket configuration can be obtained with SocketConfig.cur. You can change the system default by using SocketConfig.setCur.
See TcpSocket.make, TcpListener.make, UdpSocket.make, MulticastSocket.make
Constructors
| make | Create and configure the socket options. |
Fields
| acceptTimeout | Controls how long a TcpListener.accept will block before throwing an IOErr timeout exception. |
| broadcast | SO_BROADCAST socket option |
| connectTimeout | Controls the default timeout used by TcpSocket.connect. |
| inBufferSize | The size in bytes for the sys::InStream buffer. |
| keepAlive | SO_KEEPALIVE option |
| keystore | The KeyStore to use when creating secure sockets. |
| linger | SO_LINGER controls the linger time or set to null to disable linger. |
| noDelay | TCP_NODELAY socket option specifies that send not be delayed to merge packets (Nagle's algorthm). |
| outBufferSize | The size in bytes for the sys::OutStream buffer. |
| receiveBufferSize | SO_RCVBUF option for the size in bytes of the IP stack buffers. |
| receiveTimeout | SO_TIMEOUT controls the amount of time a socket will block on a read call before throwing an IOErr timeout exception. |
| reuseAddr | SO_REUSEADDR is used to control the time wait state of a closed socket. |
| sendBufferSize | SO_SNDBUF option for the size in bytes of the IP stack buffers. |
| trafficClass | The type-of-class byte in the IP packet header. |
| truststore | The KeyStore to use for obtaining trusted certificates when creating secure sockets. |
Methods
| copy | Create a copy of this configuration and then apply any overrides from the it-block. |
| cur | Get the current, default socket configuration |
| setCur | Set a new default socket configuration. |
| setTimeouts | Convenience to create a copy of this socket configuration and set the connect and receive timeouts to the given duration. |
Slot Details
acceptTimeout
const Duration? acceptTimeout := null
Controls how long a TcpListener.accept will block before throwing an IOErr timeout exception. null is used to indicate infinite timeout.
broadcast
const Bool broadcast := false
SO_BROADCAST socket option
connectTimeout
const Duration? connectTimeout := 1min
Controls the default timeout used by TcpSocket.connect. A null value indicates a system default timeout (usually wait forever).
copy
virtual This copy(|This| f)
Create a copy of this configuration and then apply any overrides from the it-block.
cur
static SocketConfig cur()
Get the current, default socket configuration
inBufferSize
const Int? inBufferSize := 4096
The size in bytes for the sys::InStream buffer. A value of 0 or null disables input stream buffing.
keepAlive
const Bool keepAlive := false
SO_KEEPALIVE option
keystore
const KeyStore? keystore := null
The KeyStore to use when creating secure sockets. If null, the runtime default will be used.
linger
const Duration? linger := null
SO_LINGER controls the linger time or set to null to disable linger.
make
new make(|This|? f := null)
Create and configure the socket options.
noDelay
const Bool noDelay := true
TCP_NODELAY socket option specifies that send not be delayed to merge packets (Nagle's algorthm).
outBufferSize
const Int? outBufferSize := 4096
The size in bytes for the sys::OutStream buffer. A value of 0 or null disables output stream buffing.
receiveBufferSize
const Int receiveBufferSize := 65536
SO_RCVBUF option for the size in bytes of the IP stack buffers.
receiveTimeout
const Duration? receiveTimeout := 1min
SO_TIMEOUT controls the amount of time a socket will block on a read call before throwing an IOErr timeout exception. null is used to indicate an infinite timeout.
reuseAddr
const Bool reuseAddr := false
SO_REUSEADDR is used to control the time wait state of a closed socket.
sendBufferSize
const Int sendBufferSize := 65536
SO_SNDBUF option for the size in bytes of the IP stack buffers.
setCur
static Void setCur(SocketConfig cfg)
Set a new default socket configuration. This configuration will only apply to new sockets created after this is called. This method may only be called once to change the default socket configuration.
setTimeouts
This setTimeouts(Duration? connectTimeout, Duration? receiveTimeout := connectTimeout)
Convenience to create a copy of this socket configuration and set the connect and receive timeouts to the given duration. Setting to null indicates infinite timeouts.
trafficClass
const Int trafficClass := 0
The type-of-class byte in the IP packet header.
For IPv4 this value is detailed in RFC 1349 as the following bitset:
- IPTOS_LOWCOST (0x02)
- IPTOS_RELIABILITY (0x04)
- IPTOS_THROUGHPUT (0x08)
- IPTOS_LOWDELAY (0x10)
For IPv6 this is the value placed into the sin6_flowinfo header field.
truststore
const KeyStore? truststore := null
The KeyStore to use for obtaining trusted certificates when creating secure sockets. If null, the runtime default will be used.
SocketOptions
class SocketOptions : Obj
SocketOptions groups together all the socket options used to tune a TcpSocket, TcpListener, or UdpSocket. See the options method of each of those classes for which options apply. Accessing an unsupported option for a particular socket type will throw UnsupportedErr.
Fields
| broadcast | SO_BROADCAST socket option. |
| connectTimeout | Controls default timeout used by TcpSocket.connect. |
| inBufferSize | The size in bytes for the sys::InStream buffer. |
| keepAlive | SO_KEEPALIVE socket option. |
| linger | SO_LINGER socket option controls the linger time or set to null to disable linger. |
| noDelay | TCP_NODELAY socket option specifies that send not be delayed to merge packets (Nagle's algorthm). |
| outBufferSize | The size in bytes for the sys::OutStream buffer. |
| receiveBufferSize | SO_RCVBUF option for the size in bytes of the IP stack buffers. |
| receiveTimeout | SO_TIMEOUT socket option controls the amount of time this socket will block on a read call before throwing an IOErr timeout exception. |
| reuseAddr | SO_REUSEADDR socket option is used to control the time wait state of a closed socket. |
| sendBufferSize | SO_SNDBUF option for the size in bytes of the IP stack buffers. |
| trafficClass | The type-of-class byte in the IP packet header. |
Methods
| copyFrom | Set all of this instance's options from the specified options. |
Slot Details
broadcast
Bool broadcast
SO_BROADCAST socket option.
connectTimeout
@Deprecated { msg="Use SocketConfig.connectTimeout" } Duration? connectTimeout
Controls default timeout used by TcpSocket.connect. A null value indicates a system default timeout.
copyFrom
Void copyFrom(SocketOptions options)
Set all of this instance's options from the specified options.
inBufferSize
Int? inBufferSize
The size in bytes for the sys::InStream buffer. A value of 0 or null disables input stream buffing. This field may only be set before the socket is connected otherwise Err is thrown.
keepAlive
Bool keepAlive
SO_KEEPALIVE socket option.
linger
Duration? linger
SO_LINGER socket option controls the linger time or set to null to disable linger.
noDelay
Bool noDelay
TCP_NODELAY socket option specifies that send not be delayed to merge packets (Nagle's algorthm).
outBufferSize
Int? outBufferSize
The size in bytes for the sys::OutStream buffer. A value of 0 or null disables output stream buffing. This field may only be set before the socket is connected otherwise Err is thrown.
receiveBufferSize
Int receiveBufferSize
SO_RCVBUF option for the size in bytes of the IP stack buffers.
receiveTimeout
Duration? receiveTimeout
SO_TIMEOUT socket option controls the amount of time this socket will block on a read call before throwing an IOErr timeout exception. Null is used to indicate an infinite timeout.
reuseAddr
Bool reuseAddr
SO_REUSEADDR socket option is used to control the time wait state of a closed socket.
sendBufferSize
Int sendBufferSize
SO_SNDBUF option for the size in bytes of the IP stack buffers.
trafficClass
Int trafficClass
The type-of-class byte in the IP packet header.
For IPv4 this value is detailed in RFC 1349 as the following bitset:
- IPTOS_LOWCOST (0x02)
- IPTOS_RELIABILITY (0x04)
- IPTOS_THROUGHPUT (0x08)
- IPTOS_LOWDELAY (0x10)
For IPv6 this is the value placed into the sin6_flowinfo header field.
TcpListener
class TcpListener : Obj
TcpListener is a server socket that listens to a local well known port for incoming TcpSockets.
Constructors
| make | Create a new, unbound TCP server socket. |
Methods
| accept | Accept the next incoming connection. |
| bind | Bind this listener to the specified local address. |
| close | Close this server socket. |
| config | The SocketConfig being used to configure the server sockets. |
| isBound | Is this socket bound to a local address and port. |
| isClosed | Is this socket closed. |
| localAddr | Get the bound local address or null if unbound. |
| localPort | Get the bound local port or null if unbound. |
| options | Access the SocketOptions used to tune this server socket. |
Slot Details
accept
TcpSocket accept()
Accept the next incoming connection. This method blocks the calling thread until a new connection is established. If this listener's SocketConfig.acceptTimeout is configured, then accept will timeout with an IOErr.
bind
This bind(IpAddr? addr, Int? port, Int backlog := 50)
Bind this listener to the specified local address. If addr is null then the default IpAddr for the local host is selected. If port is null an ephemeral port is selected. Throw IOErr if the port is already bound or the bind fails. Return this.
close
Bool close()
Close this server socket. This method is guaranteed to never throw an IOErr. Return true if the socket was closed successfully or false if the socket was closed abnormally.
config
SocketConfig config()
The SocketConfig being used to configure the server sockets.
isBound
Bool isBound()
Is this socket bound to a local address and port.
isClosed
Bool isClosed()
Is this socket closed.
localAddr
IpAddr? localAddr()
Get the bound local address or null if unbound.
localPort
Int? localPort()
Get the bound local port or null if unbound.
make
new make(SocketConfig config := SocketConfig.cur())
Create a new, unbound TCP server socket. The socket will be configured using the given socket configuration. The following configuration applies to listeners:
SocketConfig.receiveBufferSizeSocketConfig.reuseAddrSocketConfig.acceptTimeout
options
@Deprecated { msg="Use SocketConfig" } SocketOptions options()
Access the SocketOptions used to tune this server socket. The following options apply to TcpListeners:
- receiveBufferSize
- reuseAddr Accessing other option fields will throw UnsupportedErr.
TcpSocket
class TcpSocket : Obj
TcpSocket manages a TCP/IP endpoint.
Constructors
| make | Make a new unbound, unconnected TCP socket. |
Methods
| bind | Bind this socket to the specified local address. |
| close | Close this socket and its associated IO streams. |
| config | Get the socket configuration for this socket. |
| connect | Connect this socket to the specified address and port. |
| in | Get the input stream used to read data from the socket. |
| isBound | Is this socket bound to a local address and port. |
| isClosed | Is this socket closed. |
| isConnected | Is this socket connected to the remote host. |
| localAddr | Get the bound local address or null if unbound. |
| localPort | Get the bound local port or null if unbound. |
| options | Access the SocketOptions used to tune this socket. |
| out | Get the output stream used to write data to the socket. |
| remoteAddr | Get the remote address or null if not connected. |
| remotePort | Get the remote port or null if not connected. |
| shutdownIn | Place input stream for socket at "end of stream". |
| shutdownOut | Disables the output stream for this socket. |
| upgradeTls | Get a new TCP socket that is upgraded to use TLS. |
Slot Details
bind
This bind(IpAddr? addr, Int? port)
Bind this socket to the specified local address. If addr is null then the default IpAddr for the local host is selected. If port is null an ephemeral port is selected. Throw IOErr if the port is already bound or the bind fails. Return this.
close
Bool close()
Close this socket and its associated IO streams. This method is guaranteed to never throw an IOErr. Return true if the socket was closed successfully or false if the socket was closed abnormally.
config
SocketConfig config()
Get the socket configuration for this socket.
connect
This connect(IpAddr addr, Int port, Duration? timeout := this.config().connectTimeout)
Connect this socket to the specified address and port. This method will block until the connection is made. Throw IOErr if there is a connection error. If a non-null timeout is specified, then block no longer then the specified timeout before raising an IOErr. If timeout is null, then a system default is used. The default timeout is configured via SocketConfig.connectTimeout.
in
InStream in()
Get the input stream used to read data from the socket. The input stream is automatically buffered according to SocketOptions.inBufferSize. If not connected then throw IOErr.
isBound
Bool isBound()
Is this socket bound to a local address and port.
isClosed
Bool isClosed()
Is this socket closed.
isConnected
Bool isConnected()
Is this socket connected to the remote host.
localAddr
IpAddr? localAddr()
Get the bound local address or null if unbound.
localPort
Int? localPort()
Get the bound local port or null if unbound.
make
new make(SocketConfig config := SocketConfig.cur())
Make a new unbound, unconnected TCP socket. The socket will be configured using the given socket configuration. The following configuration applies to a TCP socket:
SocketConfig.inBufferSizeSocketConfig.outBufferSizeSocketConfig.keepAliveSocketConfig.receiveBufferSizeSocketConfig.sendBufferSizeSocketConfig.reuseAddrSocketConfig.lingerSocketConfig.receiveTimeoutSocketConfig.noDelaySocketConfig.trafficClass
options
@Deprecated { msg="Use SocketConfig" } SocketOptions options()
Access the SocketOptions used to tune this socket. The following options apply to TcpSockets:
- inBufferSize
- outBufferSize
- keepAlive
- receiveBufferSize
- sendBufferSize
- reuseAddr
- linger
- receiveTimeout
- noDelay
- trafficClass Accessing other option fields will throw UnsupportedErr.
out
OutStream out()
Get the output stream used to write data to the socket. The output stream is automatically buffered according to SocketOptions.outBufferSize If not connected then throw IOErr.
remoteAddr
IpAddr? remoteAddr()
Get the remote address or null if not connected.
remotePort
Int? remotePort()
Get the remote port or null if not connected.
shutdownIn
Void shutdownIn()
Place input stream for socket at "end of stream". Any data sent to input side of socket is acknowledged and then silently discarded. Raise IOErr if error occurs.
shutdownOut
Void shutdownOut()
Disables the output stream for this socket. Any previously written data will be sent followed by TCP's normal connection termination sequence. Raise IOErr if error occurs.
upgradeTls
TcpSocket upgradeTls(IpAddr? addr := null, Int? port := null)
Get a new TCP socket that is upgraded to use TLS. If connecting through a web proxy, specify the destination address and port.
UdpPacket
class UdpPacket : Obj
UdpPacket encapsulates an IpAddr, port, and payload of bytes to send or receive from a UdpSocket.
Constructors
| make | Construct a new UdpPacket. |
Fields
| addr | The send or receive IpAddr. |
| data | The payload to send or received. |
| port | The send or receive port number. |
Slot Details
addr
IpAddr? addr := null
The send or receive IpAddr. Defaults to null.
data
Buf? data := null
The payload to send or received. Defaults to null. The data buffer must always be a memory backed buffer.
make
new make(IpAddr? addr := null, Int? port := null, Buf? data := null)
Construct a new UdpPacket.
port
Int? port := null
The send or receive port number. Defaults to null.
UdpSocket
class UdpSocket : Obj
UdpSocket manages a UDP/IP datagram endpoint.
Constructors
| make | Make a new unbound UDP socket. |
Methods
| bind | Bind this socket to the specified local address. |
| close | Close this socket. |
| config | Get the socket configuration for this socket. |
| connect | Connect this socket to the specified address and port. |
| disconnect | Disconnect this socket from its remote address. |
| isBound | Is this socket bound to a local address and port. |
| isClosed | Is this socket closed. |
| isConnected | Is this socket "connected" to a specific remote host. |
| localAddr | Get the bound local address or null if unbound. |
| localPort | Get the bound local port or null if unbound. |
| options | Access the SocketOptions used to tune this socket. |
| receive | Receive a packet on this socket's bound local address. |
| remoteAddr | Get the remote address or null if not connected to a specific end point. |
| remotePort | Get the remote port or null if not connected to a specific end point. |
| send | Send the packet to its specified remote endpoint. |
Slot Details
bind
This bind(IpAddr? addr, Int? port)
Bind this socket to the specified local address. If addr is null then the default IpAddr for the local host is selected. If port is null an ephemeral port is selected. Throw IOErr if the port is already bound or the bind fails. Return this.
close
Bool close()
Close this socket. This method is guaranteed to never throw an IOErr. Return true if the socket was closed successfully or false if the socket was closed abnormally.
config
SocketConfig config()
Get the socket configuration for this socket.
connect
This connect(IpAddr addr, Int port)
Connect this socket to the specified address and port. Once connected packets may only be send to the remote using this socket.
disconnect
This disconnect()
Disconnect this socket from its remote address. Do nothing if not connected. Return this.
isBound
Bool isBound()
Is this socket bound to a local address and port.
isClosed
Bool isClosed()
Is this socket closed.
isConnected
Bool isConnected()
Is this socket "connected" to a specific remote host. Since UDP is not session oriented, connected just means we've used connect() to predefine the remote address where we want to send packets.
localAddr
IpAddr? localAddr()
Get the bound local address or null if unbound.
localPort
Int? localPort()
Get the bound local port or null if unbound.
make
new make(SocketConfig config := SocketConfig.cur())
Make a new unbound UDP socket. The socket will be configured using the given socket configuration. The following configuration applies to UDP sockets:
SocketConfig.broadcastSocketConfig.receiveBufferSizeSocketConfig.sendBufferSizeSocketConfig.reuseAddrSocketConfig.receiveBufferSizeSocketConfig.trafficClass
options
@Deprecated { msg="Use SocketConfig" } SocketOptions options()
Access the SocketOptions used to tune this socket. The following options apply to UdpSockets:
- broadcast
- receiveBufferSize
- sendBufferSize
- reuseAddr
- receiveBufferSize
- trafficClass Accessing other option fields will throw UnsupportedErr.
receive
UdpPacket receive(UdpPacket? packet := null)
Receive a packet on this socket's bound local address. The resulting packet is filled in with the sender's address and port. This method blocks until a packet is received. If this socket's receiveTimeout option is configured, then receive will timeout with an IOErr.
The packet data is read into the Buf starting at it's current position. The buffer is not grown - at most Buf.capacity bytes are received. If the received message is longer than the packet's capacity then the message is silently truncated (weird Java behavior). Upon return the Buf size and position are updated to reflect the bytes read. Use Buf.flip to ready the buffer to read from start. If packet is null, then a new packet is created with a capacity of 1kb. The packet data must always be a memory backed buffer.
remoteAddr
IpAddr? remoteAddr()
Get the remote address or null if not connected to a specific end point.
remotePort
Int? remotePort()
Get the remote port or null if not connected to a specific end point.
send
Void send(UdpPacket packet)
Send the packet to its specified remote endpoint. If this is socket is connected to a specific remote address, then the packet's address and port must be null or ArgErr is thrown. Throw IOErr on error.
The number of bytes sent is buf.remaining; upon return the buf is drained and position is advanced.
UnknownHostErr
const class UnknownHostErr : IOErr
UnknownHostErr indicates a failure to resolve a hostname to an IP address.
Constructors
| make |
Slot Details
make
new make(Str msg, Err? cause := null)