The following describes only the error codes specific to this module. For details about the universal error codes, see Universal Error Codes.
Socket error code mapping: 2301000 + kernel error code.
Socket server error code mapping: 2303100 + kernel error code.
Error Code Description for Connection Disconnection Scenarios
Error Message
Operation not permitted.
Description
This error code is reported if an operation is not allowed.
Possible Causes
The operation is illegal.
Solution
Check the operation procedure.
Error Message
No such file or directory.
Description
This error code is reported if the requested file does not exist.
Possible Causes
The requested file does not exist.
Solution
Check the file name or file path.
Error Message
No such process.
Description
This error code is reported if a process does not exist.
Possible Causes
This error code is reported if a process does not exist.
Solution
Check the process information.
Error Message
Interrupted system call.
Description
This error code is reported if the system call is interrupted.
Possible Causes
The system call is interrupted.
Solution
Rectify system call errors.
Description of TCP/UDP error codes:
Mapping format of other TCP/UDP Socket error codes: 2301000 + Linux kernel error code (errno). For details, see Linux kernel error codes.
Error Message
System internal error.
Description
This error code is reported if a system internal error occurs.
Possible Causes
The memory is abnormal.
A null pointer is present.
Solution
Check whether the memory space is sufficient. If not, clear the memory and try again.
Check whether the system is normal. If not, try again later or restart the device.
Error Message
Socks5 failed to connect to the proxy server.
Description
This error code is reported if a SOCKS5 client fails to connect to the proxy server.
Possible Causes
The proxy server address is incorrect.
Solution
Check whether the proxy server address is correct.
Error Message
Socks5 username or password is invalid.
Description
This error code is reported if the user name or password is invalid when the SOCKS5 client uses the password authentication mode.
Possible Causes
The user name or password is incorrect.
Solution
Check whether the user name and password are correct.
Error Message
Socks5 failed to connect to the remote server.
Description
This error code is reported if a SOCKS5 proxy fails to connect to the remote server.
Possible Causes
The network of the remote server is faulty.
Solution
Check the network status of the remote server.
Error Message
Socks5 failed to negotiate the authentication mode.
Description
This error code is reported if a SOCKS5 client fails to negotiate the authentication mode with the proxy server.
Possible Causes
The proxy server does not support the authentication mode provided by the SOCKS5 client.
Solution
Check whether the proxy server supports the authentication mode provided by the SOCKS5 client.
Error Message
Socks5 failed to send the message.
Description
This error code is reported if a SOCKS5 client fails to send messages due to a system call error.
Possible Causes
This problem is usually caused by memory overflows and invalid parameters. Check the log for Linux kernel errors.
Solution
Create a socket and initiate a connection again.
Error Message
Socks5 failed to receive the message.
Description
This error code is reported if a SOCKS5 client fails to receive messages due to a system call error.
Possible Causes
This problem is usually caused by memory overflows and invalid parameters. Check the log for Linux kernel errors.
Solution
Create a socket and initiate a connection again.
Error Message
Socks5 serialization error.
Description
This error code is reported if message fails to be serialized for a SOCKS5 client.
Possible Causes
The user name or password is too long, or the address and protocol type of the proxy server and the remote server do not match.
Solution
Check whether the user name and password exceed the length limit and whether the addresses and protocol types of the proxy server and remote server match.
Error Message
Socks5 deserialization error.
Description
This error code is reported if message fails to be deserialized for a SOCKS5 client.
Possible Causes
The length of the response packets sent by the server does not comply with the protocol.
Solution
Check the response data packets of the server.
Error Message
Interrupted system call.
Description
This error code is reported if the system call is interrupted.
Possible Causes
Calling the connect function may result in a long blocking time. In such a case, the system generates an interrupt signal and returns an EINTR error.
Solution
Call the connect function to try network connection again.
Error Message
Bad file number.
Description
This error code is reported if an operation is performed on a locally closed socket.
Possible Causes
The socket FD may be closed.
Solution
Check whether the socket is closed unexpectedly.
Error Message
Bad file descriptor.
Description
The file descriptor is invalid or has been closed.
Possible Causes
The socket has been closed or destroyed.
The socket was not created correctly.
An operation was performed on a closed socket.
The socket fd was closed unexpectedly. The log prompt is poll to send failed, socket is .*, errno is 9 or fcntl F_GETFL error, errno is .*, where .* is a wildcard.
Solution
Check whether the socket is closed unexpectedly.
Ensure that the socket has been correctly created and is in a valid state before calling other methods.
If the socket has been closed, recreate the socket instance.
Error Message
Insufficient permissions.
Description
Insufficient permissions. The operation is denied.
Possible Causes
The application does not have the necessary network permission configuration (such as ohos.permission.INTERNET).
System permission restrictions, such as requiring special permissions to access specific ports.
Solution
Check whether the necessary network permissions (such as ohos.permission.INTERNET) are configured in module.json5.
Check whether the operation meets the permission requirements. You can locate this error using the log keyword "Permission denied".
Error Message
Broken pipe.
Description
Data is sent to a disconnected connection, and the peer (server or local) has closed the connection.
Possible Causes
After the server actively closes the connection, the local end still calls send to send data (errno is 32, EPIPE).
After the local end actively closes the connection, it still calls send to send data.
Solution
Determine the disconnection timing: if the server closes first, the server actively disconnects; if the local end closes first, the client actively disconnects.
Stop sending, re-establish the connection, and then send data.
Error Message
Network is down.
Description
The network is down, and the connection is disconnected.
Possible Causes
The cellular network is disconnected, there is no network signal, or airplane mode is enabled (errno is 100, ENETDOWN).
The network service is not started or has stopped.
Solution
Determine that the disconnection is caused by the cellular network or the network, not by an internal application issue.
Check the network connection status, restore the network, and then re-establish the connection.
Error Message
Network is unreachable.
Description
The network is unreachable, and the connection is disconnected.
Possible Causes
The cellular data network is unavailable or not enabled (errno is 101, ENETUNREACH).
The network route is abnormal or the gateway is unreachable.
Solution
Determine that the disconnection is caused by the cellular/network issue.
Check the network connection status, restore the network, and then re-establish the connection.
Error Message
Connection reset by peer.
Description
Connection reset by peer, which usually indicates that the server actively disconnects the connection.
Possible Causes
The server actively disconnects the connection and sends an RST (errno 104, ECONNRESET).
The server process exits abnormally, or the connection is reclaimed by the server due to timeout.
Solution
Determine that the server actively disconnects the connection.
Check the running status of the server and re-establish the connection.
Error Message
Cannot send after transport endpoint shutdown.
Description
Sending data after the local connection is closed.
Possible Causes
After the local end actively calls close or shutdown, send is still called (errno is 108, ESHUTDOWN).
Solution
Determine that this is a misoperation after the client actively disconnects.
Check the code flow to ensure that no data is sent after the connection is closed.
Error Message
Connection timed out.
Description
The connection timed out, usually caused by a weak network or cellular network issue.
Possible Causes
The weak network or poor cellular network signal prevents data from being delivered within the timeout period (errno is 110, ETIMEDOUT).
The connection is reclaimed by a network device after a long period without data interaction.
Solution
Determine that the disconnection is caused by a network issue (cellular/weak network).
Check the network quality, and re-establish the connection after the network is restored.
Error Message
No route to host.
Description
The target host is unreachable.
Possible Causes
The cellular network cannot route to the target host (errno is 113, EHOSTUNREACH).
The target server is offline or its IP address has changed.
Solution
Determine that the disconnection is caused by a network issue (cellular/router).
Check the reachability of the target host and the network status.
Error Message
Operation now in progress.
Description
A compatibility error code returned by the framework when a TCP asynchronous connection is in progress, or when the connection times out or fails.
Possible Causes
A TCP asynchronous connection is in progress (errno is 115, EINPROGRESS), and the final connection result has not been returned.
When TCPSocket.connect times out or fails, the framework uniformly returns EINPROGRESS (compatibility handling).
This error code may also be returned when LocalSocket.connect times out or fails.
Solution
If the connection is still in progress, wait for the connect callback or the 'connect' event before performing subsequent operations.
If the connection has timed out, check the network connection status and the peer service status, and re-establish the connection.
Error Message
Operation would block.
Description
The operation may block.
Possible Causes
A blocking operation is executed on a non-blocking socket (errno 11, EAGAIN).
The socket send buffer is full, or the current resource is temporarily unavailable.
Solution
Wait until the socket is writable and try again.
Check the socket status and resource usage.
Error Message
Invalid argument.
Description
Invalid argument.
Possible Causes
The passed parameter is invalid (errno is 22, EINVAL).
The passed IP address, port, or socket option value is incorrect.
Solution
Check whether the value and format of the passed parameter are correct.
Reset the parameter by referring to the API parameter description.
Error Message
Not a socket.
Description
A socket operation was executed on a non-socket file descriptor.
Possible Causes
The socket was not created correctly or has been destroyed (errno 88, ENOTSOCK).
An operation was executed on a closed socket.
Solution
Check whether the socket is created correctly and not closed.
Re-create the socket and then perform the operation.
Error Message
Address already in use.
Description
Network address already in use.
Possible Causes
The bound local address is already occupied by another socket (errno is 98, EADDRINUSE).
The port has not been released and is still in the TIME_WAIT state.
Solution
Change the bound address or port.
Wait for the port to be released or close the connection that occupies the port.
Error Message
Cannot assign requested address.
Description
Cannot allocate requested address.
Possible Causes
The bound IP address does not belong to the local host (errno is 99, EADDRNOTAVAIL).
The specified local address is invalid or unavailable.
Solution
Check whether the bound IP address is a local host address.
Replace it with an available local address.
Error Message
Connection refused.
Description
Connection refused.
Possible Causes
No process is listening on the target address (errno is 111, ECONNREFUSED).
The target server is not started, or the firewall rejects the connection request.
Solution
Confirm that the target server is started and listening on the corresponding port.
Check the network firewall or security policy configuration.
Error Message
Socket operation on non-socket.
Description
This error code is reported if a socket descriptor is not specified for the socket parameter.
Possible Causes
A socket descriptor is not specified for the socket parameter.
Solution
Check whether the descriptor is correctly obtained.
Error Message
Incorrect socket protocol type.
Description
This error code is reported if the type of the specified socket protocol is incorrect.
Possible Causes
The socket function is called with an unsupported socket protocol type. For example, the protocol type cannot be set to SOCK_STREAM socket for the Internet UDP protocol.
Solution
Check whether the socket protocol type is correct.
Error Message
Address already in use.
Description
This error code is reported if a network address has been used.
Possible Causes
The probable cause can be any of the following: The application attempts to bind a socket to an IP address/port that has been used for an existing socket. The socket is not properly closed. The socket is still being closed.
Solution
Try another network address.
Error Message
Cannot assign requested address.
Description
This error code is reported if the requested address is invalid in its context.
Possible Causes
The remote address or port is invalid for the remote server.
Solution
Check whether the address or port is correct.
Error Message
Network is down.
Description
This error code is reported if the network is disabled.
Possible Causes
The network service is not started or has been stopped.
Solution
Check the network connection.
Error Message
Socket is not connected.
Description
An operation that requires a connection is executed on a socket for which no connection has been established.
Possible Causes
An operation such as sending is executed before the connection is established (errno is 107, ENOTCONN).
The connection has been disconnected, but an operation is still executed on the socket.
Solution
Establish the connection first, and then execute the related operation.
Check the connection status and re-establish the connection if necessary.
Error Message
Connection timed out.
Description
This error code is reported if the connection to the remote server cannot be set up for a long time.
Possible Causes
It is probable that a server breakdown has occurred.
Solution
If the issue cannot be resolved locally, verify whether the remote server has encountered a fault.
Error Message
SSL is null.
Description
The SSL object is null.
Possible Causes
The TLSSocket.connect method was not called.
The TLSSocket.connect method failed to execute.
The SSL connection was not established successfully.
The TLSSocket was not bound correctly (the bind method was not called). The log prompt is "tlsSocket is null".
Solution
Ensure that the TLSSocket.connect method is called successfully before calling other methods.
Check the execution result of the connect method to ensure that the connection has been established successfully.
If connect fails, locate the cause of the failure and try to connect again.
Error Message
An error occurred when reading data on the TLS socket.
Description
An error occurs when reading data from the TLS socket.
Possible Causes
The underlying socket is blocked.
Solution
Perform data receiving again.
Error Message
An error occurred when writing data on the TLS socket.
Description
An error occurs when writing data to the TLS socket.
Possible Causes
When the sender buffer is full, the underlying socket send operation returns the EWOULDBLOCK error, which means that the server has not read the message sent from the client.
Solution
Check the server status, and rectify the fault.
Error Message
An error occurred when verifying the X.509 certificate.
Description
An error occurred when verifying the x509 certificate.
Possible Causes
The local certificate does not match the server certificate.
Solution
Check whether the local CA root certificate matches the server certificate.
Error Message
An error occurred in the TLS system call.
Description
An unrecoverable fatal I/O error occurred in the TLS system call.
Possible Causes
A network issue caused the communication failure.
The underlying socket is abnormal.
An error occurred during the TLS handshake.
The socket was closed during a TLS operation. The log prompt is poll to recv failed, socket is .*, errno is .* or recv fail, socket:.*, errno:.*, where .* is a wildcard. Common errno values for reference: errno=9 (EBADF, invalid file descriptor), errno=104 (ECONNRESET, connection reset), errno=110 (ETIMEDOUT, connection timed out), errno=111 (ECONNREFUSED, connection refused).
Solution
Refer to the general kernel error code errno in the log for detailed information.
Check the network connection status.
Try to re-establish the TLS connection.
Error Message
Failed to close the TLS connection.
Description
Failed to close the TLS connection.
Possible Causes
The TLS/SSL connection to be closed has been disabled.
Solution
Initiate a new TLS/SSL connection.
Error Message
Invalid socket FD.
Description
The socket file descriptor is invalid.
Possible Causes
The socket is not created correctly or has been closed.
An operation is executed on a destroyed socket.
Solution
Check whether the socket is valid.
Re-create the socket and then perform the operation.
Error Message
Socket is not connected.
Description
The socket is not connected.
Possible Causes
An operation that requires a connection is executed before the connection is established.
The operation continues after the connection is closed.
Solution
Establish the connection before executing the operation.
Check the connection status and initiate the connection again.