Structs
struct AddressFamily
public struct AddressFamily <: ToString & Equatable<AddressFamily> {
public static const INET = AddressFamily("INET", 2)
public static const INET6: AddressFamily
public static const NETLINK: AddressFamily
public static const UNIX = AddressFamily("UNIX", 1)
public static const UNSPEC = AddressFamily("UNSPEC", 0)
public let name: String
public let value: Int32
public const init(name: String, value: UInt16)
}
Description: Indicates the AddressFamily address family for the addressing scheme of Socket. The commonly used address families are INET, INET6, and UNIX. An address family identifier is initially defined in RFC 2453.
Parent types:
static const INET
public static const INET = AddressFamily("INET", 2)
Description: Specifies the IPv4 address family.
Type: AddressFamily
static const INET6
public static const INET6: AddressFamily
Description: Specifies the IPv6 address family. Values on different OSs are as follows:
- macOS: AddressFamily("INET6", 30)
- Windows: AddressFamily("INET6", 23)
- Others: AddressFamily("INET6", 10)
Type: AddressFamily
static const NETLINK
public static const NETLINK: AddressFamily
Description: Specifies the NetLink address family that is supported only on Linux. The value is as follows:
- Linux: AddressFamily("NETLINK", 16)
Type: AddressFamily
static const UNIX
public static const UNIX = AddressFamily("UNIX", 1)
Description: Specifies the Unix Domain Socket address family.
Type: AddressFamily
static const UNSPEC
public static const UNSPEC = AddressFamily("UNSPEC", 0)
Description: Indicates that no address family is specified.
Type: AddressFamily
let name: String
public let name: String
Description: Specifies an address family name.
Type: String
let value: UInt16
public let value: UInt16
Description: Specifies an address family value.
Type: UInt16
init(String, UInt16)
public const init(name: String, value: UInt16)
Description: Specifies the constant constructor for creating an AddressFamily object.
Parameters:
func toString()
public func toString(): String
Description: Obtains the name corresponding to an address family.
Returns:
- String: name of the current address family
operator func ==(AddressFamily)
public operator func ==(rhs: AddressFamily): Bool
Description: Checks whether address family values are equal.
Parameters:
- rhs: AddressFamily: AddressFamily object for comparison
Returns:
- Bool: If the two AddressFamily objects are equal,
trueis returned. Otherwise,falseis returned.
operator func !=(AddressFamily)
public operator func !=(rhs: AddressFamily): Bool
Description: Checks whether address family values are not equal.
Parameters:
- rhs: AddressFamily: AddressFamily object for comparison
Returns:
- Bool: If the two AddressFamily objects are not equal,
trueis returned. Otherwise,falseis returned.
struct OptionLevel
public struct OptionLevel {
public static const ICMP: Int32 = 1
public static const IP: Int32 = 0
public static const RAW: Int32 = 255
public static const SOCKET: Int32
public static const TCP: Int32 = 6
public static const UDP: Int32 = 17
}
Description: Provides common socket option levels.
static const ICMP
public static const ICMP: Int32 = 1
Description: Specifies the socket option level that controls the ICMP protocol behavior.
Type: Int32
static const IP
public static const IP: Int32 = 0
Description: Specifies the socket option level that controls the IP protocol behavior.
Type: Int32
static const RAW
public static const RAW: Int32 = 255
Description: Specifies the socket option level that controls the RAW protocol behavior.
Type: Int32
static const SOCKET
public static const SOCKET: Int32
Description: Specifies the socket option level that controls the basic socket behavior. Values on different OSs are as follows:
- macOS: 0xFFFF
- Windows: 0xFFFF
- Others: 1
Type: Int32
static const TCP
public static const TCP: Int32 = 6
Description: Specifies the socket option level that controls the TCP protocol behavior.
Type: Int32
static const UDP
public static const UDP: Int32 = 17
Description: Specifies the socket option level that controls the UDP protocol behavior.
Type: Int32
struct OptionName
public struct OptionName {
public static const IP_HDRINCL: Int32
public static const IP_TOS: Int32
public static const IP_TTL: Int32
public static const SO_ACCEPTCONN: Int32
public static const SO_BROADCAST: Int32
public static const SO_DEBUG: Int32 = 0x0001
public static const SO_DONTROUTE: Int32
public static const SO_ERROR: Int32
public static const SO_KEEPALIVE: Int32
public static const SO_LINGER: Int32
public static const SO_OOBINLINE: Int32
public static const SO_RCVBUF: Int32
public static const SO_RCVTIMEO: Int32
public static const SO_REUSEADDR: Int32
public static const SO_SNDBUF: Int32
public static const SO_SNDTIMEO: Int32
public static const TCP_KEEPCNT: Int32
public static const TCP_KEEPIDLE: Int32
public static const TCP_KEEPINTVL: Int32
public static const TCP_NODELAY: Int32 = 0x0001
}
Description: Provides common socket options.
static const IP_HDRINCL
public static const IP_HDRINCL: Int32
Description: Specifies whether the IP header is provided by the application when a data packet is sent. Values on different OSs are as follows:
- macOS: 0x0002
- Windows: 0x0002
- Others: 0x0003
Type: Int32
static const IP_TOS
public static const IP_TOS: Int32
Description: Specifies the data packet service type and priority. Values on different OSs are as follows:
- macOS: 0x0003
- Windows: 0x0003
- Others: 0x0001
Type: Int32
static const IP_TTL
public static const IP_TTL: Int32
Description: Specifies the maximum number of hops for transmitting IP data packets on the network. Values on different OSs are as follows:
- macOS: 0x0004
- Windows: 0x0004
- Others: 0x0002
Type: Int32
static const SO_ACCEPTCONN
public static const SO_ACCEPTCONN: Int32
Description: Queries whether a socket is in the listening state. Values on different OSs are as follows:
- macOS: 0x0002
- Windows: 0x0002
- Others: 0x001E
Type: Int32
static const SO_BROADCAST
public static const SO_BROADCAST: Int32
Description: Specifies whether a socket is allowed to send broadcast messages. Values on different OSs are as follows:
- macOS: 0x0020
- Windows: 0x0020
- Others: 0x0006
Type: Int32
static const SO_DEBUG
public static const SO_DEBUG: Int32 = 0x0001
Description: Enables or disables the debug mode.
Type: Int32
static const SO_DONTROUTE
public static const SO_DONTROUTE: Int32
Description: Avoids routing socket data packets during socket connection. Values on different OSs are as follows:
- macOS: 0x0010
- Windows: 0x0010
- Others: 0x0005
Type: Int32
static const SO_ERROR
public static const SO_ERROR: Int32
Description: Obtains and clears the error state of a socket. Values on different OSs are as follows:
- macOS: 0x1007
- Windows: 0x1007
- Others: 0x0004
Type: Int32
static const SO_KEEPALIVE
public static const SO_KEEPALIVE: Int32
Description: Checks whether the TCP connection is still active. Values on different OSs are as follows:
- macOS: 0x0008
- Windows: 0x0008
- Others: 0x0009
Type: Int32
static const SO_LINGER
public static const SO_LINGER: Int32
Description: Sets the behavior when a socket is closed. Values on different OSs are as follows:
- macOS: 0x0080
- Windows: 0x0080
- Others: 0x000D
Type: Int32
static const SO_OOBINLINE
public static const SO_OOBINLINE: Int32
Description: Controls the mode of receiving out-of-band data. Values on different OSs are as follows:
- macOS: 0x0100
- Windows: 0x0100
- Others: 0x000A
Type: Int32
static const SO_RCVBUF
public static const SO_RCVBUF: Int32
Description: Sets the size for the socket to receive buffer. Values on different OSs are as follows:
- macOS: 0x1002
- Windows: 0x1002
- Others: 0x0008
Type: Int32
static const SO_RCVTIMEO
public static const SO_RCVTIMEO: Int32
Description: Sets the timeout interval for the socket to receive data. Values on different OSs are as follows:
- macOS: 0x1006
- Windows: 0x1006
- Others: 0x0014
Type: Int32
static const SO_REUSEADDR
public static const SO_REUSEADDR: Int32
Description: Releases the bound port immediately after the socket is closed so that other sockets can be immediately bound to the port. Values on different OSs are as follows:
- macOS: 0x0004
- Windows: 0x0004
- Others: 0x0002
Type: Int32
static const SO_SNDBUF
public static const SO_SNDBUF: Int32
Description: Sets the size for the socket to send buffer. Values on different OSs are as follows:
- macOS: 0x1001
- Windows: 0x1001
- Others: 0x0007
Type: Int32
static const SO_SNDTIMEO
public static const SO_SNDTIMEO: Int32
Description: Sets the timeout interval for the socket to send data. Values on different OSs are as follows:
- macOS: 0x1005
- Windows: 0x1005
- Others: 0x0015
Type: Int32
static const TCP_KEEPCNT
public static const TCP_KEEPCNT: Int32
Description: Controls the number of keepalive probe packets sent in a TCP connection. Values on different OSs are as follows:
- macOS: 0x0102
- Windows: 0x0010
- Others: 0x0006
Type: Int32
static const TCP_KEEPIDLE
public static const TCP_KEEPIDLE: Int32
Description: Specifies the maximum number of times that TCP connections can be maintained when no acknowledgment is received from the peer end. Values on different OSs are as follows:
- macOS: 0x0010
- Windows: 0x0003
- Others: 0x0004
Type: Int32
static const TCP_KEEPINTVL
public static const TCP_KEEPINTVL: Int32
Description: Sets the interval for sending probe packets during TCP connection maintenance. Values on different OSs are as follows:
- macOS: 0x0101
- Windows: 0x0011
- Others: 0x0005
Type: Int32
static const TCP_NODELAY
public static const TCP_NODELAY: Int32 = 0x0001
Description: Controls the delay behavior of the TCP protocol.
Type: Int32
struct ProtocolType
public struct ProtocolType <: Equatable<ProtocolType> & ToString & Hashable {
public static let ICMP: ProtocolType = ProtocolType(1)
public static let IPV4: ProtocolType = ProtocolType(4)
public static let IPV6: ProtocolType = ProtocolType(41)
public static let RAW: ProtocolType = ProtocolType(255)
public static let TCP: ProtocolType = ProtocolType(6)
public static let UDP: ProtocolType = ProtocolType(17)
public static let Unspecified: ProtocolType = ProtocolType(0)
public init(protocol: Int32)
}
Description: Provides common socket protocols and supports constructing socket protocols by specifying the Int32 value.
Parent types:
static let ICMP
public static let ICMP: ProtocolType = ProtocolType(1)
Description: Specifies the protocol type as ICMP.
Type: ProtocolType
static let IPV4
public static let IPV4: ProtocolType = ProtocolType(4)
Description: Specifies the protocol type as IPv4.
Type: ProtocolType
static let IPV6
public static let IPV6: ProtocolType = ProtocolType(41)
Description: Specifies the protocol type as IPv6.
Type: ProtocolType
static let RAW
public static let RAW: ProtocolType = ProtocolType(255)
Description: Specifies the protocol type as RAW.
Type: ProtocolType
static let TCP
public static let TCP: ProtocolType = ProtocolType(6)
Description: Specifies the protocol type as TCP.
Type: ProtocolType
static let UDP
public static let UDP: ProtocolType = ProtocolType(17)
Description: Specifies the protocol type as UDP.
Type: ProtocolType
static let Unspecified
public static let Unspecified: ProtocolType = ProtocolType(0)
Description: Indicates that no protocol type is specified.
Type: ProtocolType
init(Int32)
public init(protocol: Int32)
Description: Creates a protocol by specifying the socket protocol value.
Parameters:
- protocol: Int32: socket protocol value
func hashCode()
public func hashCode(): Int64
Description: Returns the hash value of the current ProtocolType instance.
Returns:
- Int64: hash value of the current ProtocolType instance
func toString()
public func toString(): String
Description: Returns the string that represents the current ProtocolType instance.
Returns:
- String: string that represents the current ProtocolType instance
operator func !=(ProtocolType)
public operator func !=(r: ProtocolType): Bool
Description: Checks whether two ProtocolType instances are not equal.
Parameters:
- r: ProtocolType: ProtocolType instance for comparison
Returns:
- Bool: If the Int32 values represented by the two instances are not equal,
trueis returned. Otherwise,falseis returned.
operator func ==(ProtocolType)
public operator func ==(r: ProtocolType): Bool
Description: Checks whether two ProtocolType instances are equal.
Parameters:
- r: ProtocolType: ProtocolType instance for comparison
Returns:
- Bool: If the Int32 values represented by the two instances are equal,
trueis returned. Otherwise,falseis returned.
struct RawAddress
public struct RawAddress {
public init(addr: Array<Byte>)
}
Description: Provides the functionalities for creating and obtaining RawSocket communication address instances.
prop addr
public prop addr: Array<Byte>
Description: Obtains an address.
init(Array<Byte>)
public init(addr: Array<Byte>)
Description: Creates an address based on a byte array.
Parameters:
struct SocketDomain
public struct SocketDomain <: Equatable<SocketDomain> & ToString & Hashable {
public static let IPV4: SocketDomain = SocketDomain(2)
public static let IPV6: SocketDomain
public static let NETLINK: SocketDomain = SocketDomain(16)
public static let PACKET: SocketDomain = SocketDomain(17)
public static let UNIX: SocketDomain
public init(domain: Int32)
}
Description: Provides common socket communication domains and supports constructing socket communication domains by specifying the Int32 value.
Parent types:
static let IPV4
public static let IPV4: SocketDomain = SocketDomain(2)
Description: Specifies the IPv4 communication domain.
Type: SocketDomain
static let IPV6
public static let IPV6: SocketDomain
Description: Specifies the IPv6 communication domain. Values on different OSs are as follows:
- macOS: SocketDomain(30)
- Windows: SocketDomain(23)
- Others: SocketDomain(10)
Type: SocketDomain
static let NETLINK
public static let NETLINK: SocketDomain = SocketDomain(16)
Description: Specifies the communication between the kernel and the user space processes.
NOTE
- This constant is not provided on Windows or macOS.
Type: SocketDomain
static let PACKET
public static let PACKET: SocketDomain = SocketDomain(17)
Description: Allows user space programs to directly access network data packets.
NOTE
- This constant is not provided on Windows or macOS.
Type: SocketDomain
static let UNIX
public static let UNIX: SocketDomain
Description: Specifies local communication. Values on different OSs are as follows:
- Windows: SocketDomain(0)
- Others: SocketDomain(1)
Type: SocketDomain
init(Int32)
public init(domain: Int32)
Description: Creates a socket communication domain based on the specified communication domain value.
Parameters:
- domain: Int32: communication domain value
func hashCode()
public func hashCode(): Int64
Description: Returns the hash value of the current SocketDomain instance.
Returns:
- Int64: hash value of the current SocketDomain instance
func toString()
public func toString(): String
Description: Returns the string that represents the current SocketDomain instance.
Returns:
- String: string that represents the current SocketDomain instance
operator func !=(SocketDomain)
public operator func !=(r: SocketDomain): Bool
Description: Checks whether two SocketDomain instances are not equal.
Parameters:
- r: SocketDomain: SocketDomain instance for comparison
Returns:
- Bool: If the Int32 values represented by the two instances are not equal,
trueis returned. Otherwise,falseis returned.
operator func ==(SocketDomain)
public operator func ==(r: SocketDomain): Bool
Description: Checks whether two SocketDomain instances are equal.
Parameters:
- r: SocketDomain: SocketDomain instance for comparison
Returns:
- Bool: If the Int32 values represented by the two instances are equal,
trueis returned. Otherwise,falseis returned.
struct SocketKeepAliveConfig
public struct SocketKeepAliveConfig <: ToString & Equatable<SocketKeepAliveConfig> {
public let count: UInt32
public let idle: Duration
public let interval: Duration
public init(idle!: Duration = Duration.second * 45, interval!: Duration = Duration.second * 5, count!: UInt32 = 5)
}
Description: Specifies TCP KeepAlive attribute configurations.
Parent types:
let count
public let count: UInt32
Description: Specifies the number of packets for querying whether the connection is invalid.
Type: UInt32
let idle
public let idle: Duration
Description: Specifies the idle duration of a connection. If the duration exceeds the specified value, the connection is closed.
Type: Duration
let interval
public let interval: Duration
Description: Specifies the interval for sending keepalive packets.
Type: Duration
init(Duration, Duration, UInt32)
public init(idle!: Duration = Duration.second * 45, interval!: Duration = Duration.second * 5, count!: UInt32 = 5)
Description: Initializes a SocketKeepAliveConfig instance object.
Parameters:
- idle!: Duration: allowed idle duration. The default value is 45 seconds.
- interval!: Duration: keepalive packet sending interval. The default value is 45 seconds.
- count!: UInt32: number of packets for querying whether the connection is invalid. The default value is 5.
Throws:
- IllegalArgumentException: If the idle state is configured or the interval is less than 0, this exception is thrown.
func toString()
public override func toString(): String
Description: Translates the TCP KeepAlive attribute into a string.
Returns:
- String: string after translation
operator func !=(SocketKeepAliveConfig)
public override operator func !=(other: SocketKeepAliveConfig): Bool
Description: Checks whether two SocketKeepAliveConfig instances are not equal.
Parameters:
- other: SocketKeepAliveConfig: SocketKeepAliveConfig instance for comparison
Returns:
- Bool: If the two instances are not equal,
trueis returned. Otherwise,falseis returned.
operator func ==(SocketKeepAliveConfig)
public override operator func ==(other: SocketKeepAliveConfig): Bool
Description: Checks whether two SocketKeepAliveConfig instances are equal.
Parameters:
- other: SocketKeepAliveConfig: SocketKeepAliveConfig instance for comparison
Returns:
- Bool: If the two instances are equal,
trueis returned. Otherwise,falseis returned.
struct SocketOptions
public struct SocketOptions {
public static const IPPROTO_TCP: Int32 = 6
public static const IPPROTO_UDP: Int32 = 17
public static const SOL_SOCKET: Int32
public static const SO_BINDTODEVICE: Int32
public static const SO_KEEPALIVE: Int32
public static const SO_LINGER: Int32
public static const SO_RCVBUF: Int32
public static const SO_REUSEADDR: Int32
public static const SO_REUSEPORT: Int32
public static const SO_SNDBUF: Int32
public static const TCP_NODELAY: Int32 = 0x0001
public static const TCP_QUICKACK: Int32
}
Description: Specifies the SocketOptions struct that contains some parameter constants for setting socket options to facilitate subsequent calls.
const IPPROTO_TCP (deprecated)
public static const IPPROTO_TCP: Int32 = 6
Description: Sets level of a socket option to IPPROTO_TCP.
NOTE
This constant will be deprecated in future releases and OptionLevel.TCP will be used instead.
Type: Int32
const IPPROTO_UDP (deprecated)
public static const IPPROTO_UDP: Int32 = 17
Description: Sets level of a socket option to IPPROTO_UDP.
NOTE
This constant will be deprecated in future releases and OptionLevel.UDP will be used instead.
Type: Int32
const SOL_SOCKET (deprecated)
public static const SOL_SOCKET: Int32
Description: Sets level of a socket option to SOL_SOCKET. Values on different OSs are as follows:
- macOS: 0xFFFF
- Windows: 0xFFFF
- Others: 1
NOTE
This constant will be deprecated in later versions and OptionLevel.SOCKET will be used instead.
Type: Int32
const SO_BINDTODEVICE
public static const SO_BINDTODEVICE: Int32
Description: Sets optname of a socket option to SO_BINDTODEVICE. Values on different OSs are as follows:
- macOS: 0xFFFF
- Windows: 0xFFFF
- Others: 0x0019
Type: Int32
const SO_KEEPALIVE
public static const SO_KEEPALIVE: Int32
Description: Sets optname of a socket option to SO_KEEPALIVE. Values on different OSs are as follows:
- macOS: 0x0008
- Windows: 0x0008
- Others: 0x0009
Type: Int32
const SO_LINGER
public static const SO_LINGER: Int32
Description: Sets optname of a socket option to SO_LINGER. Values on different OSs are as follows:
- macOS: 0x0080
- Windows: 0x0080
- Others: 0x000D
Type: Int32
const SO_RCVBUF
public static const SO_RCVBUF: Int32
Description: Sets optname of a socket option to SO_RCVBUF. Values on different OSs are as follows:
- macOS: 0x1002
- Windows: 0x1002
- Others: 0x0008
Type: Int32
const SO_REUSEADDR
public static const SO_REUSEADDR: Int32
Description: Sets optname of a socket option to SO_REUSEADDR. Values on different OSs are as follows:
- macOS: 0x0004
- Windows: 0x0004
- Others: 0x0002
Type: Int32
const SO_REUSEPORT
public static const SO_REUSEPORT: Int32
Description: Sets optname of a socket option to SO_REUSEPORT. Values on different OSs are as follows:
- macOS: 0x0200
- Windows: 0xFFFF
- Others: 0x000F
Type: Int32
const SO_SNDBUF
public static const SO_SNDBUF: Int32
Description: Sets optname of a socket option to SO_SNDBUF. Values on different OSs are as follows:
- macOS: 0x1001
- Windows: 0x1001
- Others: 0x0007
Type: Int32
const TCP_NODELAY
public static const TCP_NODELAY: Int32 = 0x0001
Description: Sets optname of a socket option to TCP_NODELAY.
Type: Int32
const TCP_QUICKACK
public static const TCP_QUICKACK: Int32
Description: Sets optname of a socket option to TCP_QUICKACK. Values on different OSs are as follows:
- macOS: 0xFFFF
- Windows: 0xFFFF
- Others: 0x000C
Type: Int32
struct SocketType
public struct SocketType <: Equatable<SocketType> & ToString & Hashable {
public static let DATAGRAM: SocketType = SocketType(2)
public static let RAW: SocketType = SocketType(3)
public static let SEQPACKET: SocketType = SocketType(5)
public static let STREAM: SocketType = SocketType(1)
public init(`type`: Int32)
}
Description: Provides common socket types and supports constructing socket types by specifying the Int32 value.
Parent types:
static let DATAGRAM
public static let DATAGRAM: SocketType = SocketType(2)
Description: Specifies the datagram socket type.
Type: SocketType
static let RAW
public static let RAW: SocketType = SocketType(3)
Description: Specifies the raw socket type.
Type: SocketType
static let SEQPACKET
public static let SEQPACKET: SocketType = SocketType(5)
Description: Specifies the sequenced packet socket type.
Type: SocketType
static let STREAM
public static let STREAM: SocketType = SocketType(1)
Description: Specifies the stream socket type.
Type: SocketType
init(Int32)
public init(`type`: Int32)
Description: Creates a socket type by specifying the socket type value.
Parameters:
- `type`: Int32: socket type value
func hashCode()
public func hashCode(): Int64
Description: Returns the hash value of the current SocketType instance.
Returns:
- Int64: hash value of the current SocketType instance
func toString()
public func toString(): String
Description: Returns the string that represents the current SocketType instance.
Returns:
- String: string that represents the current SocketType instance
operator func !=(SocketType)
public operator func !=(r: SocketType): Bool
Description: Checks whether two SocketType instances are not equal.
Parameters:
- r: SocketType: SocketType instance for comparison
Returns:
- Bool: If the Int32 values represented by the two instances are not equal,
trueis returned. Otherwise,falseis returned.
operator func ==(SocketType)
public operator func ==(r: SocketType): Bool
Description: Checks whether two SocketType instances are equal.
Parameters:
- r: SocketType: SocketType instance for comparison
Returns: