std.net
Overview
The net package provides functionalities including starting the Socket server, connecting to the Socket server, sending data, and receiving data, and supports data structures about IP addresses, IP prefixes (also known as IP subnets), and Socket addresses for network communications.
Three Socket types of UDP, TCP, and UDS are supported. You can select a type as required.
The User Datagram Protocol (UDP) is a connectionless transmission protocol, which does not provide reliability or flow control, but features low latency and low network overhead. The UDP is mainly used in application scenarios with high real-time requirements, such as live video streaming and online gaming.
The Transmission Control Protocol (TCP) is a connection-oriented and reliable transmission protocol. As one of commonly used transmission protocols on Internet, it provides functionalities such as reliable data transmission, flow control, congestion control, error detection, and flow management.
The 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
Interfaces
| Name | Description |
|---|---|
| DatagramSocket | Indicates a socket for receiving and reading data packets. |
| ServerSocket | Provides APIs required by Socket of the server. |
| StreamingSocket | Specifies Socket running in duplex stream mode, which can be read or written. |
Classes
| Name | Description |
|---|---|
| IPAddress | Indicates the Internet Protocol (IP) address. |
| IPPrefix | Indicates an IP prefix (also called IP subnet), which is a consecutive IP address block with the boundary being a power of 2. |
| IPSocketAddress | Implements an IP protocol socket address (IP address+port number). |
| IPv4Address | Indicates an Internet protocol version 4 (IPv4) address. |
| IPv6Address | Indicates an Internet protocol version 6 (IPv6) address. |
| RawSocket | Provides basic functions of a socket. |
| SocketAddress | Indicates a protocol-independent socket address. |
| TcpServerSocket | Specifies a server that listens for TCP connections. |
| TcpSocket | Specifies a client that requests a TCP connection. |
| UdpSocket | Provides UDP packet communication. |
| UnixDatagramSocket | Provides the host communication capability based on data packets. |
| UnixServerSocket | Provides a host communication server based on the duplex stream. |
| UnixSocket | Provides a host communication client based on the duplex stream. |
| UnixSocketAddress | Implements a UDS address. |
Enums
| Name | Description |
|---|---|
| SocketNet | Specifies the transport layer protocol type. |
Structs
| Name | Description |
|---|---|
| AddressFamily | Identifies an individual network address scheme or numbering plan for network communication in a context where the use of an individual address may be unclear. |
| 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 parameter constants for setting socket options to facilitate subsequent calls. |
| SocketType | Provides common socket types and allows the socket types to be constructed by specifying the value of Int32. |
Exceptions
| Name | Description |
|---|---|
| SocketException | Handles exceptions related to sockets. |
| SocketTimeoutException | Handles exceptions related to character formats. |