std.socket Package
Function Description
The socket package is used for network communication, and provides functions such as starting a Socket
server, connecting to a Socket
server, sending data, and receiving data.
Three Socket
types of UDP, TCP, and UDS are supported. You can select a type as required.
User Datagram Protocol (UDP) is a connectionless transmission protocol. It does not provide reliability or flow control, but features low delay and low network overhead. UDP is mainly used in applications with high real time requirements, such as live video streaming and online gaming.
Transmission Control Protocol (TCP) is a connection-oriented and reliable transmission protocol. As one of commonly used transmission protocols on Internet, it provides functions such as reliable data transmission, flow control, congestion control, error detection, and flow management.
Unix Domain Socket (UDS) is a mechanism used for communication between processes on one computer. Unlike network sockets, the UDS does not require network protocol stacks or network devices. Therefore, it features faster communication, lower latency and higher throughput.
The class inheritance relationship of Socket
provided by the library is as follows:
Hierarchy
Resource
├StreamingSocket
│ ├TcpSocket
│ └UnixSocket
│
├DatagramSocket
│ ├UdpSocket
│ └UnixDatagramSocket
│
└ServerSocket
├TcpServerSocket
└UnixServerSocket
API List
Constant & Variable
Name | Description |
---|---|
IPV4_ALL_ROUTER | Specifies the IPv4 multicast address. |
IPV4_ALL_SYSTEM | Specifies the IPv4 multicast address. |
IPV4_BROADCAST | Specifies the IPv4 broadcast address. |
IPV4_LOCAL_HOST | Specifies the local IPv4 address. |
IPV4_ZERO | Specifies the universal IPv4 address. |
IPV6_INTERFACE_LOCAL_ALL_NODES | Specifies the IPv6 multicast addresses of all nodes within the node-local scope. |
IPV6_LINK_LOCAL_ALL_NODES | Specifies the IPv6 multicast addresses of all nodes within the link-local scope. |
IPV6_LINK_LOCAL_ALL_ROUTERS | Specifies the IPv6 multicast addresses of all routers within the link-local scope. |
IPV6_LOOPBACK | Specifies the loopback address (local address). |
IPV6_ZERO | Specifies the universal IPv6 address. |
Interface
Name | Description |
---|---|
DatagramSocket | Specifies a socket for receiving and reading packets. |
ServerSocket | Provides APIs required by Socket of the server. |
StreamingSocket | Specifies Socket running in duplex stream mode, which is readable and writable. |
Class
Name | Description |
---|---|
IPMask | Specifies the IP mask, IP address, and routing address. |
RawSocket | Provides basic functions of a socket. |
SocketAddress | Specifies the socket address with a specific type, address, and port. |
SocketAddressWithMask | Provides SocketAddress with a mask. |
TcpServerSocket | Specifies the server that monitors TCP connections. |
TcpSocket | Specifies the client that requests a TCP connection. |
UdpSocket | Provides UDP packet communication. |
UnixDatagramSocket | Provides the packet-based host communication capability. |
UnixServerSocket | Provides a duplex stream-based server for host communication. |
UnixSocket | Provides a duplex stream-based client for host communication. |
Enumeration
Name | Description |
---|---|
SocketAddressKind | Specifies the Internet communication protocol type. |
SocketNet | Specifies the transport layer protocol type. |
Struct
Name | Description |
---|---|
OptionLevel | Provides common socket option levels. |
OptionName | Provides common socket options. |
ProtocolType | Provides common socket protocols, and allows the socket protocols to be constructed by specifying the value of Int32 . |
RawAddress | Creates and obtains the communication address of RawSocket . |
SocketDomain | Provides common socket communication domains, and allows the socket communication domains to be constructed by specifying the value of Int32 . |
SocketKeepAliveConfig | Configures the TCP KeepAlive attribute. |
SocketOptions | Stores some constants for setting socket options for subsequent calling. |
SocketType | Provides common socket types and allows the socket types to be constructed by specifying the value of Int32 . |
Exception Class
Name | Description |
---|---|
SocketException | Provides socket-related exception processing. |
SocketTimeoutException | Provides exception processing related to the character format. |