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

NameDescription
DatagramSocketIndicates a socket for receiving and reading data packets.
ServerSocketProvides APIs required by Socket of the server.
StreamingSocketSpecifies Socket running in duplex stream mode, which can be read or written.

Classes

NameDescription
IPAddressIndicates the Internet Protocol (IP) address.
IPPrefixIndicates an IP prefix (also called IP subnet), which is a consecutive IP address block with the boundary being a power of 2.
IPSocketAddressImplements an IP protocol socket address (IP address+port number).
IPv4AddressIndicates an Internet protocol version 4 (IPv4) address.
IPv6AddressIndicates an Internet protocol version 6 (IPv6) address.
RawSocketProvides basic functions of a socket.
SocketAddressIndicates a protocol-independent socket address.
TcpServerSocketSpecifies a server that listens for TCP connections.
TcpSocketSpecifies a client that requests a TCP connection.
UdpSocketProvides UDP packet communication.
UnixDatagramSocketProvides the host communication capability based on data packets.
UnixServerSocketProvides a host communication server based on the duplex stream.
UnixSocketProvides a host communication client based on the duplex stream.
UnixSocketAddressImplements a UDS address.

Enums

NameDescription
SocketNetSpecifies the transport layer protocol type.

Structs

NameDescription
AddressFamilyIdentifies an individual network address scheme or numbering plan for network communication in a context where the use of an individual address may be unclear.
OptionLevelProvides common socket option levels.
OptionNameProvides common socket options.
ProtocolTypeProvides common socket protocols and allows the socket protocols to be constructed by specifying the value of Int32.
RawAddressCreates and obtains the communication address of RawSocket.
SocketDomainProvides common socket communication domains and allows the socket communication domains to be constructed by specifying the value of Int32.
SocketKeepAliveConfigConfigures the TCP KeepAlive attribute.
SocketOptionsStores some parameter constants for setting socket options to facilitate subsequent calls.
SocketTypeProvides common socket types and allows the socket types to be constructed by specifying the value of Int32.

Exceptions

NameDescription
SocketExceptionHandles exceptions related to sockets.
SocketTimeoutExceptionHandles exceptions related to character formats.