Method for establishing network connection, electronic device, readable storage medium and chip

CN122783545APending Publication Date: 2026-09-18HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510318509.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-17
Publication Date
2026-09-18

AI Technical Summary

Technical Problem

[0005]本申请提供一种建立网络连接的方法、电子设备、可读存储介质和芯片,用于解决现有技术中电子设备建立网络连接较慢的问题

Benefits of technology

[0009] The method for establishing a network connection provided in this application allows the application to perform socket replacement at the underlying level through the operating system after initiating a network connection, directly using the socket connection in the socket connection pool for data transmission, thus enabling rapid data transfer. For example, it can quickly open the homepage when a user clicks the application icon; it can quickly communicate with the server device when a user is trying to grab tickets/red envelopes/trade stocks, increasing the likelihood of successful ticket grabbing/red envelope grabbing/stock trading; it can quickly respond to user webpage access operations and obtain application interface information; and it can also quickly respond to swiping operations on the application interface and update the interface content, providing a better user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122783545A_ABST
    Figure CN122783545A_ABST
Patent Text Reader

Abstract

This application provides a method for establishing a network connection, an electronic device, a readable storage medium, and a chip, relating to the field of communication technology. The method includes: in response to an application initiating a first network connection based on a first socket, searching for a second socket connection in a socket connection pool based on the first socket; wherein the second socket connection includes a second socket, and the second socket has the same destination IP address, destination port, and transport protocol as the first socket; replacing the first socket in the first network connection with the second socket in the second socket connection, thereby establishing the first network connection. Through the method for establishing a network connection provided by the embodiments of this application, after an application initiates a network connection, the operating system can perform socket replacement at the underlying communication link level, directly using socket connections in the socket connection pool for data transmission, enabling fast data transmission.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of communication technology, and in particular to a method for establishing a network connection, an electronic device, a readable storage medium, and a chip. Background Technology

[0002] Electronic devices contain various applications, which often require network transmission during operation, such as when launching an application, purchasing goods, updating a webpage, or downloading or updating software.

[0003] Currently, taking Transmission Control Protocol (TCP) communication as an example, the basic process of network transmission by electronic devices includes: Domain Name System (DNS) lookup, TCP connection establishment, link encryption negotiation, and information transmission. During this process, DNS lookup, TCP connection establishment, and link encryption negotiation all require network interaction and take a considerable amount of time. It is understandable that after an application initiates a network connection, the electronic device needs a considerable amount of time to establish the connection before network transmission can begin. Furthermore, in situations with poor network signal or congestion, the time required to establish a network connection will be even longer.

[0004] It's understandable that in scenarios with stringent latency requirements, a slow network connection establishment process can lead to a poor user experience. For example, in scenarios like ticket grabbing, red envelope grabbing, stock trading, or accessing the app's homepage, users may fail to grab tickets / red envelopes / stock trades, or the app's homepage may load slowly. Summary of the Invention

[0005] This application provides a method for establishing a network connection, an electronic device, a readable storage medium, and a chip to solve the problem of slow network connection establishment in existing electronic devices.

[0006] To achieve the above objectives, this application adopts the following technical solution:

[0007] In a first aspect, embodiments of this application provide a method for establishing a network connection, applied to an electronic device. The method includes: responding to an application initiating a first network connection based on a first socket, searching for a second socket connection in a socket connection pool based on the first socket; wherein the second socket connection includes a second socket, and the second socket has the same destination IP address, destination port, and transmission protocol as the first socket; replacing the first socket in the first network connection with the second socket in the second socket connection, thereby establishing the first network connection.

[0008] For example, the first network connection can be a first socket connection, a connection initiated through a connection interface, or an HTTP connection initiated through an HTTP interface. Furthermore, the socket connection pool includes established socket connections and may also include socket connections that are being established.

[0009] The method for establishing a network connection provided in this application allows the application to perform socket replacement at the underlying level through the operating system after initiating a network connection, directly using the socket connection in the socket connection pool for data transmission, thus enabling rapid data transfer. For example, it can quickly open the homepage when a user clicks the application icon; it can quickly communicate with the server device when a user is trying to grab tickets / red envelopes / trade stocks, increasing the likelihood of successful ticket grabbing / red envelope grabbing / stock trading; it can quickly respond to user webpage access operations and obtain application interface information; and it can also quickly respond to swiping operations on the application interface and update the interface content, providing a better user experience.

[0010] In some embodiments, replacing the first socket in the first network connection with the second socket to establish the first network connection includes: when the first network connection is a first socket connection, replacing the corresponding network connection information in the first socket with the network connection information in the second socket, or exchanging the network connection information in the first socket and the second socket to establish the first socket connection.

[0011] It should be noted that after an electronic device replaces the corresponding network connection information in the first socket with the network connection information in the second socket, the same network connection information will appear in both the first and second socket connections. The operating system can lock the second socket connection, preventing it from being used by the electronic device. Alternatively, the operating system can release the second socket connection.

[0012] Alternatively, after the electronic device exchanges network connection information in the first and second sockets, the second socket connection is actually unavailable. Therefore, the operating system must release the second socket connection.

[0013] In some embodiments, network connection information includes: a socket-associated sock object, a socket-associated file, the current state of the socket, a pointer to the socket's waiting signal queue, and the user identifier (UID), process name, and network interface card (NIC) information in the sock object.

[0014] In some embodiments, establishing a first network connection by replacing the first socket in the first network connection with the second socket in the second socket connection includes: when the first network connection is a connection connection, replacing the first socket-id in the connection connection with the second socket-id to establish the connection connection; when the first network connection is an HTTP connection, replacing the first socket-id in the first socket connection with the second socket-id to establish the HTTP connection; wherein the first socket-id is the identification information of the first socket, and the second socket-id is the identification information of the second socket.

[0015] According to the method of the system in this application embodiment, when an application initiates a connection / HTTP connection through the connection / HTTP interface encapsulated by the socket, the connection / HTTP interface can directly call the pre-established second socket connection at the operating system level, thereby quickly establishing a connection / HTTP connection.

[0016] In some embodiments, before the application initiates a first network connection based on the first socket, the method further includes: in response to a first event, determining the basic network information of the pre-built chain, the basic network information of the pre-built chain including a destination domain name, a destination port, and a transport protocol; performing a Domain Name System (DNS) query based on the destination domain name to determine the destination Internet Protocol (IP) address; creating a second socket based on the destination IP address, the destination port, and the transport protocol; establishing a second socket connection based on the second socket; and storing the second socket connection in a socket connection pool.

[0017] In some embodiments, the first event includes: the application calling a network interface; receiving a network task notification from the application; an artificial intelligence (AI) model predicting that a pre-established chain is needed; a user action, application event, or network event used to trigger network warm-up; recognizing target text information in a display interface / schedule information / electronic alarm clock; and receiving notification information from a server or surrounding electronic device regarding a scheduled network task.

[0018] In some embodiments, in response to a first event, determining the underlying network information of the pre-built chain includes: in response to the first event, reading the underlying network information from a local device, wherein the underlying network information is pre-configured in an electronic device; or, predicting the underlying network information using an AI model.

[0019] In some embodiments, the socket connection pool includes a user-space socket connection pool and a kernel-space socket connection pool.

[0020] In some embodiments, the second socket connection is an established or being established socket connection. It should be noted that for a socket connection that is being established, since it has already completed part of the connection establishment process, such as performing a DNS lookup or initiating a TCP SYN connection establishment request, the electronic device may also gain certain performance benefits.

[0021] In some embodiments, the socket connection pool also includes a third socket connection. The method further includes: after the third socket connection is successfully established, if the third socket connection is not used by the electronic device to transmit application data within a preset time, then the third socket connection is disconnected and deleted from the socket connection pool to save the resources of the electronic device.

[0022] In some embodiments, the method further includes: when the application is preparing to release the fourth socket connection, before releasing the fourth socket connection, recycling the fourth socket connection to the socket connection pool and delaying the release of the fourth socket connection for a preset time, so that the application can call it immediately after exiting and restarting, thereby improving the communication speed during the application restart process and improving the user experience.

[0023] In a second aspect, embodiments of this application provide an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the method shown in the first aspect above.

[0024] Thirdly, embodiments of this application provide a computer-readable storage medium storing a computer program that, when executed by a processor, implements the method shown in the first aspect above.

[0025] Fourthly, embodiments of this application provide a chip, which includes a processor and a memory. The memory stores a computer program, and when the computer program is executed by the processor, it implements the method shown in the first aspect above.

[0026] Fifthly, embodiments of this application provide a computer program product, which includes a computer program that, when executed by a processor, implements the method shown in the first aspect above.

[0027] It is understood that the beneficial effects of the second to fifth aspects mentioned above can be found in the relevant descriptions in the first aspect mentioned above, and will not be repeated here. Attached Figure Description

[0028] Figure 1A This application provides the latency required to establish a network connection in a TCP scenario as described in the embodiments of this application.

[0029] Figure 1B This refers to the latency required to establish a network connection in the UDP scenario provided in the embodiments of this application.

[0030] Figure 2 This is a schematic diagram of the structure of a communication system provided in another embodiment of this application;

[0031] Figure 3 This is a schematic diagram of the structure of an electronic device provided in one embodiment of this application;

[0032] Figure 4 This is a schematic diagram of the structure of a network prediction unit provided in one embodiment of this application;

[0033] Figure 5 This is an overall schematic diagram of the method for establishing a network connection provided in the embodiments of this application;

[0034] Figure 6 This is a schematic diagram of the AI ​​model provided in the embodiments of this application performing pre-built chain prediction;

[0035] Figure 7 This is a schematic diagram illustrating the user's usage time for different applications, provided in an embodiment of this application.

[0036] Figures 8-9 These are schematic diagrams of display interfaces including target text provided in different embodiments of this application;

[0037] Figures 10A-10B These are schematic diagrams of pre-built chains provided in different embodiments of this application;

[0038] Figure 11 This is a flowchart of a method for establishing a network connection provided in another embodiment of this application;

[0039] Figures 12A-12B These are schematic diagrams illustrating the establishment of a socket connection by an application provided in different embodiments of this application;

[0040] Figure 13 This is a schematic diagram of a socket replacement process provided in one embodiment of this application;

[0041] Figure 14 This is a schematic diagram illustrating the exchange of sock objects according to an embodiment of this application;

[0042] Figure 15This is a schematic diagram illustrating the exchange of network connection information for sockets provided in one embodiment of this application;

[0043] Figure 16 This is a schematic diagram illustrating the application establishing a connection according to an embodiment of this application;

[0044] Figure 17 This is a schematic diagram illustrating socket replacement of a connection according to an embodiment of this application;

[0045] Figure 18 This is a schematic diagram illustrating the establishment of an HTTP connection by an application according to an embodiment of this application;

[0046] Figure 19 This is a schematic diagram illustrating socket replacement of an HTTP connection according to an embodiment of this application;

[0047] Figure 20 This is a schematic diagram of the structure of a chip provided in one embodiment of this application. Detailed Implementation

[0048] It should be understood that in the description of the embodiments of this application, unless otherwise stated, " / " means "or". For example, A / B can mean A or B. The "and / or" in this document is merely a description of the relationship between related objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist simultaneously, and B exists alone.

[0049] In this embodiment, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of this embodiment, unless otherwise stated, "a plurality of" means two or more.

[0050] For ease of description, the basic concepts and terms involved in the embodiments of this application will first be introduced. It should be noted that the following description is intended for explanation and illustration, and not for limitation.

[0051] (1) socket

[0052] A socket is a mechanism in computer networks used for inter-process communication, typically for data exchange between processes on different hosts or the same host. Sockets support various protocols, such as Transmission Control Protocol (TCP) and User Datagram Protocol (UDP). A socket consists of a socket triple and a socket quintuple. The socket triple includes the destination Internet Protocol (IP) address, the destination port, and the transport protocol. The socket quintuple includes the source IP address, the source port number, the destination IP address, the destination port, and the transport protocol.

[0053] Creating a socket means that the application requests the operating system to create a socket through the socket() function. This function returns a file descriptor (fd) as a unique identifier for subsequent operations.

[0054] (2) socket-id

[0055] Operating systems or network services need to track a large number of socket connections. To manage and distinguish these connections, the operating system assigns a unique identifier, or socket-id, to each socket. The socket-id helps the system accurately identify each connection and perform connection establishment, maintenance, and closure operations. For example, when a server wants to send data to a specific client, it can find the corresponding connection through the client's socket-id. Furthermore, when sending and receiving data, programs use the socket-id to determine the source and destination of the data. For instance, when calling the `send` or `recv` function, the socket-id is used to specify the socket connection to operate on. Additionally, some operating systems define the socket-id as a socket-fd (file handle), treating the socket as a special file.

[0056] (3) User space and kernel space

[0057] In an operating system, the system is typically divided into user space and kernel space. User space is the area where ordinary applications run, while kernel space is where the operating system runs.

[0058] (4) Kernel mode and user mode

[0059] Kernel mode, also known as kernel mode, is the privileged mode in which the operating system runs. The kernel is the core of the operating system, responsible for managing system hardware resources and providing various system services, such as process scheduling, memory management, and device drivers. In kernel mode, programs can access all system hardware resources and sensitive information, and execute privileged instructions.

[0060] User mode is the normal operating mode for applications. In user mode, program operations are strictly limited; they cannot directly access system hardware resources and sensitive information, and can only request services provided by the operating system through system calls.

[0061] (5) sys-socket and user-socket

[0062] In this embodiment, sys-socket refers to a socket created by the operating system, which can reside in kernel mode or user mode. user-socket refers to a socket created by the user. It should be noted that when an operating system-created socket is in user mode, it can reside in the caller's user process or in a process of the operating system.

[0063] (7) sock

[0064] In this embodiment, a socket includes a sock. The socket faces user space, while the sock faces kernel space, and the socket and sock are interconnected. Additionally, the socket also contains information such as file operators, allowing the system to manipulate the socket like a file. The sock is the actual object related to network connections; when a user calls the socket, they ultimately call the sock for network communication.

[0065] (8) Socket connection pool

[0066] A socket connection pool is a mechanism that pre-creates and maintains socket connections for managing and reusing them. It quickly allocates connections to clients when needed and returns them to the pool after use, instead of recreating and destroying connections each time.

[0067] (9) Client and server

[0068] In this embodiment, the client is the end that actively initiates the request, typically running on a user device (such as a mobile phone, tablet, or personal computer). The server, also known as the service provider, is the end that passively receives and processes the request; it can be a user device, a server, a cloud platform, etc.

[0069] After introducing the basic concepts involved in this application, the technical solutions provided by the embodiments of this application will be described below with reference to the accompanying drawings.

[0070] Currently, electronic devices require network transmission in many usage scenarios, such as when opening applications, browsing web pages, watching short videos, long videos, live streams, sharing or backing up files, and downloading or updating software. During network transmission, electronic devices can use TCP / UDP communication according to the application's business requirements.

[0071] In some embodiments, taking an electronic device as a client for TCP communication as an example, the basic network transmission process includes, in sequence: Domain Name System (DNS) lookup, TCP connection establishment, encryption negotiation, and information transmission. The details are shown below.

[0072] (a) DNS lookup

[0073] A DNS lookup is the process of converting a human-readable domain name (such as www.huawei.com) into an Internet Protocol (IP) address that a computer can recognize and use. Typically, electronic devices first look up the IP address corresponding to the domain name in their local DNS cache. If the IP address is found in the DNS cache, it is used directly. If the IP address is not found in the DNS cache, it is then looked up on the DNS server.

[0074] (II) TCP Connection Establishment

[0075] After obtaining the IP address through a DNS lookup, the application typically creates a socket based on that IP address and initiates a socket connection by calling `connect()`. `connect()` triggers the underlying electronic device (specifically the transport layer) to establish a TCP connection. TCP connection establishment usually involves a three-way handshake. After the TCP link is established, information can be transmitted between the source and destination.

[0076] (III) Link Encryption Negotiation

[0077] Encryption negotiation refers to the process of negotiating encryption algorithms and keys after an electronic device establishes a TCP connection with the destination. This is an optional process. For example, the electronic device can perform encryption negotiation based on Transport Layer Security (TLS) version 1.2 / 1.3. Furthermore, if the electronic device is transmitting public information, or if the electronic device has already completed encryption negotiation through other dedicated links or channels, then encryption negotiation is unnecessary.

[0078] (iv) Information Transmission

[0079] In this embodiment, information transmission includes transmitting information via a TCP link, such as obtaining web page information via a TCP link or sending chat information via a TCP link.

[0080] In the aforementioned TCP communication process, DNS queries, TCP connection establishment, and encryption negotiation at the DNS server typically require network interaction, thus taking a certain amount of time. For example... Figure 1A As shown, a DNS query on a DNS server typically takes one round trip time (RTT), TCP connection establishment typically takes two RTTs, and link encryption negotiation typically takes three RTTs. Therefore, it can be understood that it usually takes 3 to 6 RTTs for an application to go from receiving a user event to transmitting data.

[0081] In other embodiments, taking an electronic device as a client for UDP communication as an example, the basic network transmission process includes: DNS lookup, socket creation, encryption negotiation, and information transmission. For details on DNS lookup and socket creation, please refer to the preceding text. Information transmission specifically includes using the `sendto()` function to send data to the server or using the `recvfrom()` function to receive a response from the server. Encryption negotiation refers to using the Datagram Transport Layer Security (DTLS) protocol for encryption negotiation.

[0082] In the above UDP process, see Figure 1B As shown. A DNS lookup by an electronic device typically takes 1 RTT. Socket creation is a local action of the electronic device and its time is negligible. Encryption negotiation typically takes 3 RTTs, but is an optional operation. Therefore, it can be understood that from receiving a user event to transmitting data, the application typically needs 1 to 4 RTTs.

[0083] It should be noted that the RTT (Round-Trip Time) varies depending on the network environment, but it is usually above 50ms. Details are as follows.

[0084] In a long term evolution (LTE) network, when the source and destination are located across provinces and at a great distance, one RTT is less than 128ms in 98% of cases, and on average is around 80ms to 100ms.

[0085] In new radio (NR) networks, when the source and destination are located in different provinces and are far apart, one RTT (Real-Time To Response) is less than 78ms in 98% of cases, with an average of around 50ms. When the source and destination are located in different provinces but are relatively close, one RTT is typically around 20ms.

[0086] Under Wireless Fidelity (WiFi), during intra-provincial communication, one RTT averages 40–80 ms; during inter-provincial communication, one RTT averages 60–100 ms; and in overseas communication scenarios, one RTT is generally over 200 ms.

[0087] Therefore, taking an RTT of 50ms as an example, in a TCP communication scenario, the application needs an average of 100-300ms to transmit information; in a UDP communication scenario, the application needs an average of 50-200ms to transmit data. It's understandable that in scenarios with stringent latency requirements, a long link preparation process before data transmission can lead to a poor user experience. For example, in scenarios like ticket grabbing, red envelope grabbing, stock trading, or entering the application's homepage, users may fail to grab tickets / red envelopes / trade stocks, or the application's homepage may load slowly.

[0088] Therefore, this application provides a method for establishing a network connection, which can speed up the process of electronic devices establishing a network connection, thereby improving the data transmission speed of applications, reducing transmission latency, and improving user experience.

[0089] First, a schematic diagram of the communication system to which the method for establishing a network connection provided in the embodiments of this application is applicable is introduced.

[0090] Figure 2 This is a schematic diagram of the structure of a communication system provided in another embodiment of this application. See also... Figure 2 As shown, the communication system includes a first electronic device, a second electronic device, and a radio access network (RAN) device. Furthermore, the first electronic device and the second electronic device communicate with each other via the RAN device.

[0091] Taking either the first or second electronic device as an example, the electronic device can be a handheld device, in-vehicle device, wearable device, or computing device with wireless communication capabilities, such as a mobile phone, tablet, laptop, PDA, mobile internet device (MID), smart bracelet, smartwatch, smart glasses, and in-vehicle system. The electronic device can also be a virtual reality (VR) electronic device, an augmented reality (AR) electronic device, a wireless electronic device in industrial control, a wireless electronic device in autonomous driving, a wireless electronic device in telemedicine, a wireless electronic device in a smart grid, a wireless electronic device in a smart city, or a wireless electronic device in a smart home.

[0092] In addition, in some embodiments, the second electronic device may also be a server device such as a web server, database server, application server, or cloud server.

[0093] RAN equipment is a device or node used to connect electronic devices to a wireless network. This wireless network can be a cellular network, a wireless local area network (WLAN) (e.g., a Wi-Fi network), a satellite network, or a Bluetooth network, etc. This application embodiment does not limit the type of wireless network.

[0094] For example, for cellular networks, the RAN device can be a base station in 5G or future communications, where a 5G base station can also be called a transmission reception point (TRP) or a next-generation node B (gNB). Alternatively, the RAN device can be an evolved node B (eNB), a radio network controller (RNC), a node B (NB), a base station controller (BSC), a base transceiver station (BTS), a home base station (e.g., a home evolved Node B, or a home Node B (HNB), a base band unit (BBU), etc. For WLAN, the RAN device can be a router, a wireless access point, a wireless repeater, a wireless extender, and a Wi-Fi access point device, etc. For satellite networks, the RAN device can be satellite equipment. For Bluetooth networks, the RAN device can be a Bluetooth gateway, a Bluetooth router, etc. The embodiments of this application do not limit the specific technology or specific device form used in the RAN device.

[0095] Based on the communication system provided in the above embodiments, when the first electronic device sends information to the second electronic device, it needs to first establish a transmission channel through the RAN, such as a WiFi transmission channel or a cellular transmission channel. Subsequently, based on the established transmission channel, the first electronic device and the second electronic device further establish a socket connection between applications or application processes, thereby realizing information transmission between applications or application processes.

[0096] In some other embodiments, the communication system may not include a RAN device, that is, the first electronic device and the second electronic device can directly establish a socket connection for communication without going through the RAN device.

[0097] Next, a schematic diagram of the electronic device to which the method for establishing a network connection provided in the embodiments of this application is applicable will be introduced.

[0098] Figure 3 This is a schematic diagram of the structure of an electronic device provided in one embodiment of this application. Figure 3 As shown, the electronic device includes an application processor and a communication processor (CP).

[0099] Application Processor (AP)

[0100] In this embodiment, the AP includes an application (App), a system interface layer, an application transport protocol stack, system services, and an underlying transport protocol. The application, system interface layer, application transport protocol stack, and system services belong to user space, while the underlying transport protocol belongs to kernel space. The various modules of the AP are described in detail below.

[0101] Applications include games, chat, messaging, calendars, cameras, navigation, photo galleries, shopping, audio / video, browsers, banking, ticketing, and payment applications.

[0102] The system interface layer serves as a communication bridge between the operating system and the external world, and it includes Kits (Development Kits). Kits encapsulate various interfaces, such as application interfaces (APIs) and database interfaces. Applications can use APIs to invoke various functions of the operating system, such as calling transport protocols in the transport protocol stack via APIs, or invoking socket connections in the user-space socket connection pool via APIs.

[0103] The application transport protocol stack includes the transport protocol and a user-space socket connection pool. Details are shown below.

[0104] Transmission Protocol These include Hypertext Transfer Protocol (HTTP), Hypertext Transfer Protocol Secure (HTTPS), QUIC (Quick UDP Internet Connections), WebSocket, and File Transfer Protocol (FTP).

[0105] User-space socket connection pool It is a socket connection pool built in user space, allowing applications to directly establish socket connections and maintain the lifecycle of the socket in user space.

[0106] The system services include a routing configuration unit, a DNS unit, a network control unit, a network prediction unit, a pre-built chain execution unit, and other modules.

[0107] It should be noted that the network prediction unit and the pre-built chain execution unit can be set up in system services or in the application transport protocol stack. The difference is that the network prediction unit and the pre-built chain execution unit in the system service can simultaneously predict and manage the pre-built chains of various applications in the electronic device, while the network prediction unit and the pre-built chain execution unit in the application transport protocol stack can only predict and manage the pre-built chains of the currently running application.

[0108] Routing Configuration Unit This includes the network daemon (NETD), which can configure and manage the device's routing table according to instructions from upper-layer applications or system services, ensuring smooth and efficient network communication.

[0109] DNS Unit This is used to perform DNS queries locally or on a DNS server and save the DNS records. These DNS records include the mapping between DNS and IP addresses, and the corresponding application. After the DNS query is complete, a socket connection can be established.

[0110] Network Control Unit This includes a migration recording subunit. This subunit records network migration information of the electronic device, such as switching or concurrent connections between Wi-Fi and cellular networks, between the primary SIM card and secondary SIM card networks, and between Wi-Fi 2.4G and Wi-Fi 5G networks. Additionally, this subunit records the network self-healing capabilities of the electronic device. Network self-healing refers to the electronic device's automatic detection, identification, and recovery from network failures (such as network loss or IP address loss).

[0111] Once electronic devices have completed network migration and self-healing, and established new connection channels between devices and completed routing configuration, Pre-DNS or Pre-Connect can be triggered. Pre-DNS refers to performing a DNS query in advance, while Pre-Connect refers to starting the establishment of a socket connection in advance.

[0112] Network prediction unit Used to predict basic network information related to pre-built chains, such as destination domain name, destination port, and transport protocol.

[0113] In this embodiment, see Figure 4 As shown, the network prediction unit includes an information identification subunit, an event and context monitoring subunit, a network interface monitoring subunit, a learning and inference subunit, a network notification and surrounding area forecast monitoring subunit, and a pre-built chain management subunit. The specific functions of each unit are shown below.

[0114] Information recognition subunit This is used to identify target text and target controls in the application interface. The target text indicates that a channel for a certain network task is about to open. The target control is used to control the execution of operations related to this event, such as a purchase control or a redemption control.

[0115] In some embodiments, the information recognition subunit can acquire a screenshot data stream of the entire screen or a portion of the screen, and use optical character recognition (OCR) technology to recognize the screenshot data stream to obtain the text information in the display interface. Alternatively, the electronic device can directly read the text in each control of the display interface. Subsequently, the target text in the application interface is recognized through template matching, regular expression matching, keyword filtering, and other methods.

[0116] In other embodiments, the information recognition subunit can obtain the schedule information (such as flash sale information) when the user manually adds it, or obtain the schedule information recorded by the user through the calendar's query interface, and recognize the target text in the schedule information. Additionally, with user authorization, the calendar can also automatically add flash sale information to the schedule.

[0117] In other embodiments, users can also add schedule information such as flash sales and transactions to the electronic alarm clock, and the information recognition subunit can obtain the schedule information through the query interface of the electronic alarm clock.

[0118] Event and Context Monitoring Subunit This system is used to monitor user events, network events, and network context information. For example, user events include the type of user event and the time of occurrence. User event types include touch events, swipe events, and in-application control operation events (such as single click, double click, long press, pressure press down events, and release up events). Network events include network card recognition and activation (i.e., network card up), data service activation, successful Wi-Fi hotspot connection, and changes in default routing information. Network context monitoring includes network self-healing, network switching, airplane mode on / off, and other network change information.

[0119] Network Interface Monitoring Subunit This system monitors the network interface layer and the application's pre-built ecosystem connection interface calls. These calls can include the type of interface called and the time of the call. The application's pre-built ecosystem connection interface can be understood as the application's information notification interface. After an event triggering the pre-built chain occurs in the application (such as detecting user input or the system obtaining the accurate time of ticket opening from the server), the application notifies the network interface monitoring subunit of this event before or during network operations, enabling the electronic device to quickly establish the pre-built chain.

[0120] Learning Reasoning Subunit This system is used to predict the start time of pre-established chains locally or in the cloud based on collected application behavior, user behavior, and network behavior, and then sends the prediction to the pre-established chain management subunit. It should be noted that if the network prediction module has already detected a user action that triggers pre-established chain establishment, the learning and inference subunit can temporarily refrain from making pre-established chain-related predictions to reduce device power consumption.

[0121] Network notification and surrounding area forecast monitoring subunit This is used to detect network notifications and surrounding area announcements. Specifically, network-side devices typically deploy scheduled network tasks. Scheduled network tasks refer to network tasks that process channels that open at regular intervals, such as ticket purchase services opening at 9:00 AM and points redemption services opening at 12:00 PM. To allow users to be aware of these scheduled network tasks in advance, network-side devices support sending advance notices of scheduled network tasks to electronic devices / users via network notifications. Electronic devices / users can subscribe to network notifications, and the network-side devices push network notifications through the PUSH channel. Alternatively, the network-side devices can push scheduled network tasks that users are interested in based on their usual content usage habits and levels of interest. Alternatively, electronic devices can proactively initiate socket connections to access the network-side devices and actively query and obtain various scheduled network tasks.

[0122] In this embodiment, the network notification includes at least the time information of the timed network task, such as start time, remaining time, time interval range, and duration. Optionally, the network notification may also include at least one of the following: task name, task description, category, application name / package name, or identifier (ID).

[0123] Surrounding notification refers to the notification information about a scheduled network task sent by surrounding electronic devices. This notification information can be generated by surrounding electronic devices or forwarded by them; this application does not restrict the source of the notification information.

[0124] Learning Reasoning Subunit This refers to an artificial intelligence (AI) model. For example, this AI model can be a neural network model, a time series AI model, such as a long short-term memory network (LSTM), a TimesNet model, or a TSMixer model.

[0125] Electronic devices can use AI models, either locally or in the cloud (i.e., on a cloud server), to learn the relationships between user behavior, application behavior, information obtained from the aforementioned sub-units, and network behavior. Based on these relationships, they can then predict the pre-built blockchain. This prediction includes forecasting the basic network information and start time of the pre-built blockchain. For example, this basic network information includes the destination domain name, destination port, transport protocol, and the number of blockchains to be built.

[0126] It should be noted that the "other sub-units" described here specifically include the information identification sub-unit, the event and context monitoring sub-unit, the network interface monitoring sub-unit, and the network notification and surrounding area warning monitoring sub-unit.

[0127] Pre-built chain management subunit This system manages matters related to pre-established chains, including determining the need for pre-establishment after receiving information identified, monitored, or predicted by the aforementioned subunits; determining the required basic network information for pre-establishment (e.g., destination domain name, destination port, transport protocol, and number of chains); and managing the start, cancellation, suspension, and termination of pre-establishment chains. For example, the pre-establishment chain management subunit sends pre-establishment instructions to the pre-establishment chain execution unit. These instructions include basic network information related to the pre-establishment chain. Optionally, the instructions may also include the start time of the pre-establishment chain.

[0128] Pre-built chain execution unit This is used to establish a socket connection based on the basic network information in the pre-established connection instruction and store it in the socket connection pool. For example, it queries the destination IP address based on the destination domain name, creates a socket based on the destination IP address, destination port, and transport protocol, and initiates a socket connection by calling the connect() function based on this socket, triggering the underlying operating system to establish a TCP connection, thereby establishing the socket connection.

[0129] The underlying transport protocols include libcurl / openssl, BSD sockets, and TCP / IP.

[0130] libcurl is an open-source client-side Uniform Resource Locator (URL) transport library that supports multiple protocols, such as HTTP, HTTPS, and FTP. OpenSSL is an open-source Secure Sockets Layer (SSL) library, an open-source cryptographic library that provides rich encryption and decryption capabilities and supports various cryptographic algorithms and protocols, such as SSL / TLS.

[0131] BSD sockets, also known as Berkeley sockets, are application programming interfaces (APIs) primarily used to enable communication between hosts on a network, as well as communication between different processes on the same computer. BSD sockets provide a standardized way to create and manage network communication endpoints.

[0132] On the server side, the main functions of BSD sockets include: creating a socket (using the `socket()` function to create a socket, which is the starting point for network communication); binding an address (using the `bind()` function to bind the socket to a specific IP address and port number so that other hosts or processes can find and communicate with it); listening for connections (using the `listen()` function to put the server-side socket into a listening state, waiting for connection requests from clients); and accepting connections (using the `accept()` function to accept client connection requests and create a new socket for communication with the client). On the client side, the main functions of BSD sockets include: creating a socket, binding an address, and initiating a connection. Binding an address is an optional function.

[0133] In addition, the main functions of BSD sockets include sending and receiving data, i.e., using functions such as send() / recv() or write() / read() to send and receive data between sockets. For connectionless sockets (such as UDP), the sendto() / recvfrom() functions can be used. And, closing the socket, i.e., using the close() function to close the socket and release system resources.

[0134] It is worth noting that in this embodiment, even if the electronic device does not include a user-space socket connection pool, BSD sockets may also include a kernel-space socket connection pool. The kernel-space socket connection pool is a socket connection pool established in kernel space, used for establishing socket connections and maintaining the socket's lifecycle in kernel space, thus implementing kernel socket mapping. The kernel-space socket connection pool is typically managed by the operating system.

[0135] TCP / IP is a set of transport protocols for achieving network interconnection. It defines the standards for how electronic devices access communication networks and how data is transmitted within those networks. It's important to note that if TCP / IP has been migrated entirely to user space, only user-space socket connection pools need to be configured; kernel-space socket connection pools are not required.

[0136] [Communication Processor CP]

[0137] In this embodiment, the CP can be a modem, a Wi-Fi chip, a Bluetooth chip, or a satellite chip, etc. The CP is used to establish a communication connection with the peer device through RAN equipment (such as a router, base station, etc.), or to establish a communication connection directly with the peer device and perform data transmission.

[0138] Based on the above-described communication system and electronic equipment, the method for establishing a network connection provided in the embodiments of this application will be described in detail below.

[0139] Figure 5 This is an overall schematic diagram of the method for establishing a network connection provided in the embodiments of this application, which specifically includes the following steps S501 to S504.

[0140] S501, the operating system pre-establishes socket connections based on predictions and stores them in a socket connection pool.

[0141] For example, the socket connection pool can be a user-space socket connection pool or a kernel-space socket connection pool.

[0142] S502, in response to the first control operation, the application creates a first socket and initiates a first network connection based on the first socket.

[0143] For example, in response to a user clicking an application icon, the application calls socket() to create a first socket and initiates a first network connection based on that first socket to load the homepage; or, in response to a user swiping or clicking on the application interface, the application calls socket() to create a first socket and initiates a first network connection based on that first socket to load a new application interface.

[0144] In this embodiment, the first network connection can be initiated by calling connect() based on the first socket, or by calling the HTTP interface based on the first socket to initiate an HTTP connection, or by calling the connection interface based on the first socket to initiate a connection connection.

[0145] S503, in response to the application initiating a first network connection, the operating system searches for an established second socket connection in the socket connection pool. The second socket connection includes a second socket, and the second socket has the same destination IP address, destination port, and transport protocol as the first socket.

[0146] S504, the operating system replaces the first socket in the first network connection with the second socket, thereby establishing the first network connection.

[0147] Since the server device has established a connection with the second socket, after replacing the first socket with the second socket, the first network connection can use the second socket for network transmission. For example, the server device can send homepage information to the electronic device's application through the first network connection so that the electronic device can display it.

[0148] It should be noted that after the application finishes using the first network connection, the operating system can reclaim the first network connection to the socket connection pool for keep-alive for later use, or delay its release.

[0149] The network connection establishment method provided in this application allows applications to quickly transmit data directly using the established socket connection without performing DNS queries, TCP connection establishment, or encryption negotiation after initiating a network connection. For example, it can quickly open the homepage when a user clicks the application icon, quickly communicate with the server device when a user is trying to grab tickets / red envelopes / trade stocks, increasing the likelihood of successful ticket / red envelope / stock transactions, and quickly rebuild the link after the electronic device switches networks, providing a better user experience.

[0150] Furthermore, since this application replaces the socket information at the network connection layer through the operating system, the application does not need to change its original interface calling method, nor does it need to call the socket connection pool through a special communication interface. Therefore, the application is unaware of the link replacement process and it will not affect the normal operation of the application.

[0151] Based on the above description, the method for establishing a network connection provided in this application mainly involves the following four parts: the first part is the prediction of pre-established links, the second part is the pre-established links, the third part is the seamless replacement of links when the application initiates a network connection, and the fourth part is link management. Each part will be described in detail below.

[0152] Part 1: Predictions for Pre-built Chains

[0153] In this embodiment, pre-establishment of a connection refers to the process of establishing a communication connection in advance before the application initiates a network connection. Pre-establishment prediction includes determining whether it is necessary to start establishing the communication connection in advance; and, if it is determined that pre-establishment is necessary, determining the basic network information for the pre-establishment connection. This prediction task is typically performed by the network prediction module in the AP.

[0154] In this embodiment, the electronic device can determine that pre-establishment of the chain is required after detecting the first event. For example, the first event includes at least one of the following (1-1) to (1-5).

[0155] (1-1) The AI ​​model predicts that pre-built chains are needed.

[0156] In this embodiment, see Figure 6 As shown, electronic devices can use artificial intelligence (AI) models to learn the relationship between user behavior, application behavior, and network behavior locally, in the cloud (i.e., cloud server), or on other electronic devices, thereby predicting network behavior based on current user and application behavior and determining whether pre-built chains are needed.

[0157] For example, the AI ​​model can be a neural network model, a time series AI model, such as a long short-term memory network (LSTM), a TimesNet model, a TSMixer model, etc.

[0158] The following section provides a detailed explanation of user behavior, application behavior, and network behavior involved in AI model learning and inference.

[0159] User behavior mainly involves a sequence of user actions. This sequence includes a series of information related to the user's actions, such as the name of the application the user is using, the time of use (e.g., start time, end time, and duration), the location of use, the network environment (e.g., Wi-Fi and data services), and the type of user command (e.g., swipe, tap, and long press).

[0160] It's important to note that the location and network environment can influence the server's selection and pre-establishment strategy. Specifically, network environments vary across locations, including signal strength, latency, bandwidth, and congestion. AI models can pre-learn the relationships between different locations and network environments, and select appropriate pre-establishment targets based on the electronic device's location. For example, when an electronic device is at home, it can reduce concerns about data charges and battery life, choosing a pre-established Wi-Fi network, or employing a more aggressive pre-establishment strategy. A more aggressive strategy might involve starting pre-establishment earlier or increasing the number of pre-established networks.

[0161] In addition, the AI ​​model can also make pre-built network predictions based on the type of business. For example, for ticket-grabbing, flash sale, low-data-volume, or low-latency businesses, cellular 5G networks will be used first. For business such as application downloads and updates, Wi-Fi networks will be used first. Furthermore, for certain designated businesses, such as one-click login, cellular networks will be used exclusively.

[0162] Application behavior refers to the business functions performed by an application in response to user control operations. Examples include opening the application's homepage, loading homepage content, sending pictures in a chat interface, making audio or video calls, making payments through a payment application, displaying weather forecasts through a weather application, playing short videos, displaying text and image news, playing live streams, and running the scan function.

[0163] Network behavior refers to the interaction between an application and network-side devices when implementing business functions. For example, this network behavior includes initiating DNS requests, establishing TCP connections, and initiating request commands (e.g., HTTP / HTTPS / WEBSOCKET / QUIC) and other pre-establishment factors. Information related to network behavior includes the set / time of DNS requests, the number and destination ports of TCP connections, whether the local port is specified, and the encryption method.

[0164] In some embodiments, taking a user's workday as an example, for instance... Figure 7 As shown, user behavior and application behavior are as follows:

[0165] Between 6:30 and 7:30, while using the home Wi-Fi network, I turned on my phone screen and then opened a news app to read the news and a weather app to check the weather forecast.

[0166] Between 8:00 and 8:30, while commuting to work (such as on the bus / subway), use cellular data to play short videos.

[0167] Between 8:40 and 9:00, I checked my Moments on the chat app while using the company's Wi-Fi network.

[0168] From 9:50 to 10:30, use office applications on the company's Wi-Fi network.

[0169] Around 11:00, I used a chat application to send and receive chat messages on the company's Wi-Fi network.

[0170] Around 11:50, I used a payment app to pay for my meal using the company cafeteria's cellular network.

[0171] From 12:00 to 1:30, use a short video app to play short videos on the company's Wi-Fi network.

[0172] Around 15:50, I used a payment app to pay for my meal using the company cafeteria's cellular network.

[0173] From 16:00 to 16:20, use a short video app to play short videos on the company's Wi-Fi network.

[0174] Around 5:10 PM, I used a chat application to send and receive chat messages on the company's Wi-Fi network.

[0175] Between 18:00 and 18:30, while commuting to work (such as on a bus or subway), use cellular data to play short videos.

[0176] Around 19:10, I used a chat application to send and receive chat messages on my home Wi-Fi network.

[0177] From 8:00 PM to 10:00 PM, use a short video app to play short videos on your home Wi-Fi network.

[0178] From 22:00 to 22:20, I opened a news app to read the news while using my home Wi-Fi network.

[0179] At 23:00, control the phone to turn off the screen / power off.

[0180] Electronic devices can generate user profiles based on user behavior and application behavior, and combine these user profiles to make predictions based on pre-built chains. For example, they can generate profiles based on the time dimension, such as profiles for weekdays, weekends, during-work hours, after-work hours, and Monday workdays.

[0181] (1-2) Used to trigger user events, application events, or network events that pre-built chains.

[0182] In this embodiment, the user event can trigger the electronic device to send data using the network. For example, the user event could be an operation by the user on a message sending control, an operation on an application download control, an operation on an application update control, a user clicking to scan and opening the camera, or a user opening the gallery interface from a chat application and selecting to send an image / video / file, etc. This embodiment does not impose specific limitations on these operations. The user's operation on the message sending control includes clicking, swiping, etc.

[0183] In some embodiments, for a control on the interface, such as a ticket-grabbing control, the electronic device typically determines that the user has clicked the control after detecting that the user has pressed and released the control (i.e., detecting an up event), and then initiates a network task such as ticket grabbing. To further improve the speed of initiating network tasks, the electronic device confirms that the user has clicked the control as soon as it detects that the user has pressed the control (i.e., detecting a down event), without needing to detect that the user's hand has released the control (i.e., without detecting an up event).

[0184] In other embodiments, the electronic device can also trigger a pre-established chain when it detects that a user has pressed a relevant control (i.e., a down event is detected). Subsequently, when it detects that the user's hand has left the control (i.e., an up event is detected), it triggers a network task command (e.g., a ticket-grabbing command). In this way, the electronic device can prioritize the pre-established chain so that the IP packets corresponding to the network task can be sent quickly afterwards.

[0185] In this embodiment, the application event can be DNS request completion, application download, application update, application installation, application cold start, application warm start, application launch of the scan function, or completion of the scan task, etc.

[0186] When an application needs to initiate a network connection, it must first send a DNS request to perform a DNS lookup. DNS request completion means the application successfully obtains the IP address corresponding to the DNS. Once the application has the IP address, it will initiate a connection establishment request. Therefore, upon receiving the DNS request response, the system can synchronously trigger pre-connection establishment behavior. Of course, to improve the hit rate, the electronic device needs to learn in advance information such as the number of connections, the destination port, the connection method, and whether a fixed port is configured on the local end.

[0187] It should be noted that after an application is downloaded, updated, or installed, users typically open and use it. Since applications usually require network access during use, a pre-established communication link for sending uplink data can be created before the user opens the application, either after the electronic device detects the application download / update / installation task, during the download / update / installation process, or after the download / update / installation is complete. Furthermore, an application cold start refers to starting the application from its initial state, loading all necessary resources, configurations, and data. An application warm start refers to the process of restarting or refreshing an application that is already running. During a warm start, the application may attempt to restore part of its previous state rather than completely reloading. Therefore, cold starts typically take longer than warm starts. Both cold and warm starts may require network access; therefore, this application uses application cold and warm starts as triggering conditions to pre-establish the communication link.

[0188] In some operating systems, applications must request network access permissions before they can access the network. For example, in HarmonyOS, applications need to request ohos.permission.INTERNET permission before accessing the network. Therefore, the access point (AP) can read the application's permission configuration file or confirm its network access permissions in advance based on information such as the application name / package name. If an application does not have network access permissions, there is no need to pre-build a link for that application.

[0189] In this embodiment, network events include network switching, network self-healing, and network context recovery. Details are as follows.

[0190] Network switching can be a process such as switching from Wi-Fi to cellular networks, switching from the primary SIM card to the secondary SIM card in an electronic device, switching from Wi-Fi 2.4G to Wi-Fi 5G, Wi-Fi roaming, or switching from one Wi-Fi hotspot to another. Network switching can immediately trigger pre-established links.

[0191] In some embodiments, electronic devices can predict pre-established links by combining the triggering reasons for the current network handover, which can further improve the accuracy of the prediction. For example, if a user is watching a video and the system initiates a network handover from a cellular network to a Wi-Fi network due to reasons such as buffering, transport layer anomalies, or air interface anomalies, the CP can initiate pre-established links while sending a notification to the application after the network handover is completed.

[0192] Network self-healing refers to the restoration of normal network functionality after an anomaly occurs. It primarily involves system-initiated self-healing retries on the signaling plane or media plane (e.g., network transport layer, chip air interface layer). For example, when network congestion is severe, it may trigger network and cell selection again, and data service activation and IP acquisition may be re-initiated. It should be noted that network self-healing will cause all previous connections to be disconnected. Therefore, after network self-healing, if the network activities prior to self-healing have not been completed, a pre-established link will be triggered.

[0193] Network context recovery refers to the process by which electronic devices restore network connectivity after changes in the network channel, IP address, or IP address interruption, using the link information from before the network change as input. It should be noted that during network context recovery, changes in the physical channel may necessitate re-updating the remote server IP address via DNS requests.

[0194] (1-3) The target text information is identified in the display interface / calendar information / electronic alarm clock.

[0195] In this embodiment, the target text information is used to indicate that a certain node is about to begin, for example... Figure 8 The text in (a) indicates "September 26th, 10:08 AM start time for the flash sale". Figure 8 The following are examples of redemption options, as shown in (b): "Redemption starts at 0 days, 0 minutes, and 33 seconds," "Friday," "Purchase starts at XX:XX," "Bonuses are replenished on the Xth, XXth, and XXth of each month at XX:00," "XX minutes and XX seconds until the next sales start time," "Coming Soon: XX Month XX Day XX:XX," and "Purchase starts at XX:00 daily." Additionally, [the following are examples of redemption options]... Figure 8For example, in the schedule information shown, “Purchase concert tickets at 12:00 noon on December 26, 2024”, “Purchase at 12:00 noon on December 26, 2024” is the target text.

[0196] (1-4) Receive notification information from the server or surrounding electronic devices regarding scheduled network tasks.

[0197] Servers typically deploy various scheduled network tasks, such as flash sales and live streaming tasks. If an electronic device subscribes to these scheduled network tasks, the server will push notifications of these tasks to the device via a PUSH channel. Alternatively, the server can match user preferences for different types of content and their browsing habits to push network notifications for network tasks that the user is interested in. Furthermore, electronic devices can proactively initiate connections via sockets, websockets, or HTTP to access the server and actively query and retrieve network notifications for various scheduled network tasks.

[0198] After determining the need for pre-establishing a link based on the above content (1-1) to (1-4), the electronic device also needs to determine the basic network information for the pre-established link. This basic network information includes at least one destination domain name, destination port, and transmission protocol (such as IPv4 / IPv6). In addition, the basic network information may also include the number of links corresponding to each domain name, link type (such as TCP, UDP), and whether the link is encrypted.

[0199] In some embodiments, the pre-built blockchain management subunit of an electronic device can use an AI model to learn the basic network information of various applications in different usage scenarios and store it locally or in the cloud for use by itself or other electronic devices. For example, the electronic device can store the basic network information used by an application in scenarios such as flash sales, payments, and page refreshes locally or in the cloud. For basic network information stored in the cloud, the electronic device can download or update the basic network information from the cloud periodically or after each power-on. For basic network information stored locally, the electronic device can directly read it when performing pre-built blockchain prediction.

[0200] In other embodiments, the developers of electronic devices can communicate with application developers to determine the basic network information of the application in various use cases, or determine the basic network information of the application in various scenarios by analyzing the application's messages, and configure it locally or in the cloud for use by various electronic devices.

[0201] In other embodiments, the application may expose an ecosystem interface or an application configuration file, which includes basic network information, triggering events, and related time information for the pre-built chain. Based on this, after a pre-built chain triggering event occurs in the application, the application notifies the pre-built chain management subunit of the corresponding basic network information and related time information through the ecosystem interface before or during network operations, enabling the electronic device to quickly perform pre-built chain construction.

[0202] For example, the configuration file can be an Extensible Markup Language (XML) file. The relevant time information is optional; it can be a preset time, such as the pre-establishment of the chain after the application has successfully started and this preset time has elapsed. Additionally, the triggering event for pre-establishing the chain can be a user input event, obtaining the accurate time of ticket opening from the server, the application starting up, the application starting successfully, or the application starting successfully and a preset time elapsed (e.g., 1 second, 3 seconds), etc.

[0203] After determining the basic network information for the pre-established link, the electronic device sends a pre-established link instruction to the pre-established link execution unit. This instruction instructs the pre-established link execution unit to establish a socket link based on the basic network information.

[0204] In summary, this embodiment is not limited to triggering pre-built chains during application startup, thus avoiding network congestion during application startup. Furthermore, this application considers various factors such as network environment and user habits during the pre-built chain process, possessing rich prediction methods and relatively accurate prediction results, which can improve the prediction hit rate and reduce invalid pre-built chains.

[0205] Part Two: Establishing a Socket Connection in Advance

[0206] In this embodiment, the electronic device pre-establishes socket connections in response to a pre-establishment link instruction and stores them in a socket connection pool. This socket connection pool can be located in user space or kernel space. Based on prediction, the electronic device can establish one socket connection or multiple socket connections in advance. Alternatively, the electronic device can establish multiple socket connections centrally when the application starts, or it can pre-establish links based on the user's usage preferences for various network functions in the application (e.g., frequency, order, and timing). That is, this embodiment does not specifically limit the timing of socket pre-establishment.

[0207] The following section explains the pre-establishment process for electronic devices based on different socket connection pools.

[0208] Figure 10A This is a flowchart illustrating the pre-establishment of a connection in an electronic device according to an embodiment of this application. In this embodiment, the socket connection pool is located in the kernel space and is a kernel-mode socket connection pool. Figure 10A As shown, in user space, after receiving the pre-establishment chain instruction, the pre-establishment chain execution unit performs a DNS query through the DNS unit to obtain the destination IP address. After a successful DNS response, the pre-establishment chain execution unit establishes a network connection (e.g., netlink) with the kernel space and instructs the operating system to perform pre-establishment chain. In kernel space, the operating system initiates sys-socket creation and connection (create & connect) based on network connection information such as the destination IP address, destination port, and transport protocol, thereby establishing a socket connection. Finally, the socket connection is stored in the kernel-mode socket connection pool.

[0209] Figure 10B This is a flowchart illustrating pre-establishing a connection for an electronic device according to another embodiment of this application. In this embodiment, the socket connection pool is set in user space and is a user-mode socket connection pool. Figure 10B As shown, in user space, after receiving the pre-establishment chain instruction, the pre-establishment chain execution unit performs a DNS query through the DNS unit to obtain the destination IP address. After a successful DNS response, the pre-establishment chain execution unit instructs the user-space socket connection pool to perform pre-establishment chain. The user-space socket connection pool initiates socket creation and connection based on network connection information such as the destination IP address, destination port, and transport protocol, thereby establishing a socket connection. Finally, the user-space socket connection pool stores this socket connection.

[0210] In this embodiment, when the electronic device stores a socket connection in the socket connection pool, it can be a complete socket entity or a sock object. This application embodiment does not impose any restrictions on this.

[0211] It should be noted that the socket pre-establishment process provided in this application embodiment is executed by the operating system, and the application does not need to perform pre-establishment on its own, nor does the application need to adapt to a specific pre-established connection port.

[0212] Part 3: Seamless link replacement when the application initiates a network connection

[0213] Figure 11 This is a flowchart of a method for establishing a network connection according to another embodiment of this application. The method includes the following steps S1101 to S1104, as detailed below.

[0214] S1101, the application of the electronic device creates the first socket.

[0215] When an application needs to transmit data, it first needs to call the socket() function to create a socket for network transmission, such as the first socket. Taking TCP communication as an example, the first socket includes a socket 5-tuple, namely the source IP address, source port number, destination IP address, destination port, and transport protocol.

[0216] S1102, the application of the electronic device initiates the first network connection based on the first socket.

[0217] In this embodiment, the first network connection can be a first socket connection, a connection connection, or an HTTP connection. Based on this, the application can initiate a first socket connection by calling the `connect()` function, or by calling the encapsulated connection interface, or by calling the encapsulated HTTP interface. It should be noted that the underlying implementation of the connection and HTTP connections still relies on sockets.

[0218] S1103, the operating system of the electronic device searches for a second socket connection in the socket connection pool, which uses the same destination IP address, destination port and transport protocol as the first network connection.

[0219] The socket connection pool includes at least one socket connection that is being established or has already been established, such as the second socket connection mentioned above. After initiating the first socket connection, the operating system of the electronic device searches for the second socket connection in the socket connection pool based on the socket triplet (i.e., destination IP address, destination port, and transport protocol) in the first socket. If the second socket connection is not found, the operating system triggers the underlying layer to establish the first network connection with the server device. If the second socket connection is found, the next step S1104 is executed.

[0220] S1104, the electronic device replaces the first socket in the first network connection with the second socket in the second socket connection, thereby establishing the first network connection.

[0221] In some embodiments, when the first network connection is a first socket connection, the network connection information in the first socket of the first socket connection is replaced with the network connection information in the second socket of the second socket connection to establish the first socket connection. For example, the network connection information includes a socket-associated sock object, a file associated with the socket, the current state of the socket, a pointer to the socket's waiting signal queue, and the user identifier (UID), process name, and network interface card (NIC) information in the sock object.

[0222] In other embodiments, when the first network connection (connection) or HTTP connection is established, the first socket in the first socket connection is completely replaced by the second socket in the second socket connection. For example, if the first socket object corresponds to the first socket-id and the second socket object corresponds to the second socket-id, the operating system can use the second socket-id to replace the first socket-id, thereby establishing the first network connection.

[0223] It should be noted that in S1104, in addition to replacing the first socket in the first socket connection with the second socket in the second socket connection, the electronic device can also exchange the second socket and the first socket. For example, it can exchange the network connection information in the second socket and the first socket, or directly exchange the socket-id of the second socket and the first socket.

[0224] The method for establishing network connections provided in this application is seamless for applications when electronic devices replace socket links. Applications do not need to call the socket connection pool through a special interface, nor do they need to add or change other interfaces, thus adapting to various types of applications.

[0225] The method for establishing a network connection provided in this application allows the application to quickly transmit data after initiating a network connection. This is because the operating system replaces the socket information at the underlying communication link level, allowing data transmission directly using an established or in-process socket connection. For example, it can quickly open the homepage when a user clicks the application icon; it can quickly communicate with the server device when a user is trying to grab tickets / red envelopes / trade stocks, increasing the likelihood of successful ticket grabbing / red envelope grabbing / stock trading; it can quickly respond to user webpage access operations and obtain application interface information; and it can quickly respond to swiping operations on the application interface and update the interface content, providing a better user experience.

[0226] The process of establishing a network connection will be explained in detail below, taking into account different scenarios such as the first network connection being a first socket connection, a connection connection, and an HTTP connection.

[0227] Case 1: The first network connection is the first socket connection.

[0228] In this embodiment, the process of establishing a socket connection by the application differs depending on the location of the socket connection pool. The following sections will explain this process in detail, using examples of the socket connection pool being located in kernel space and user space.

[0229] Figure 12A This is a schematic diagram illustrating the establishment of a socket connection by an application according to an embodiment of this application. In this embodiment, the socket connection pool is located in kernel space. Figure 12A As shown, when an application initiates the first socket connection, it first calls the `socket()` function to create the first socket and obtain the first socket-id. Subsequently, the application process initiates a system call (e.g., a syscall) through the `connect()` function. The operating system, based on the socket triple (destination IP address, destination port, and transport protocol) in the `connect()` function, searches for the second socket connection in the kernel-mode socket connection pool. Finally, within kernel space, the operating system replaces the first socket in the first socket connection with the second socket from the second socket connection, thus establishing the first socket connection.

[0230] It should be noted that since the socket connection pool is located in kernel space, the search for and replacement of the second socket connection must be performed in kernel space. Furthermore, during the process of finding the second socket connection, the operating system can search not only for established socket connections but also for socket connections that are currently being established.

[0231] Figure 12B This is a schematic diagram illustrating the establishment of a socket connection by an application according to another embodiment of this application. In this embodiment, the socket connection pool is located in user space. Figure 12BAs shown, when an application initiates the first socket connection, it first calls the `socket()` function to create the first socket and obtain the first socket-id. Then, the application initiates a system call (e.g., a syscall) via the `connect()` function. Next, the operating system establishes a network connection (e.g., a netlink) with the user-space socket connection pool. Subsequently, the operating system searches for a second socket connection in the user-space socket connection pool based on this netlink. Finally, within kernel space, the operating system replaces the first socket in the first socket connection with the second socket from the second socket connection, thereby establishing the first socket connection.

[0232] In this embodiment, when an application initiates a first socket connection, the operating system replaces the first socket in the first socket connection with the second socket in the second socket connection to establish the first socket connection. Specifically, the operating system uses the network connection information in the second socket in the second socket connection to replace the corresponding network connection information in the first socket in the first socket connection, thereby establishing the first network connection. Alternatively, the operating system exchanges the network connection information of the second socket and the first socket to establish the first network connection.

[0233] It should be noted that, in scenarios where the first network connection is the first socket connection, the electronic device must release the second socket connection after performing the aforementioned socket replacement or exchange.

[0234] The following example, using the exchange of network connection information between the first and second sockets by the operating system kernel, will illustrate this process in detail.

[0235] Figure 13 This is a schematic diagram illustrating a socket replacement process provided in one embodiment of this application. For example... Figure 13 As shown, when an application initiates the first socket connection, the operating system kernel exchanges socket information. Specifically, the BSD socket unit exchanges network connection information between the first and second sockets. The first socket refers to the socket used by the application to initiate the first network connection. The second socket refers to the socket used for the second connection.

[0236] The following details the specific process of exchanging network connection information between user-socket and sys-socket.

[0237] (3-1) First socket

[0238] The first socket refers to the socket used when the application initiates its first network connection. The application process can call the first socket with socket-fd=2 using socket-fd. Here, socket-fd is the file description (fd) of the socket, equivalent to the socket-id shown earlier. In the implementation function of the system call, socket-fd=2 is mapped to a structure representing the socket (i.e., struct socket), which includes all the attributes and data of the user-socket.

[0239] For example, the first socket should include at least the following:

[0240]

[0241] In a struct socket, a struct file must include at least the following:

[0242]

[0243] Since the socket is associated with a file object during creation, the corresponding file object can be found using the file descriptor (fd). The private data within the file object is the socket itself. Specifically, the file descriptor is used to search for the matching file object in the file descriptor structure (struct fdtable). struct fdtable includes various file descriptor tables and an unsigned int max_fds (representing the maximum capacity of the file descriptor table). The file descriptor table is an array with indices from 0 to max_fds-1, each index corresponding to a file descriptor. Each fd[i] points to a struct file structure. The application process can find the corresponding struct file in the struct fdtable by setting fd=2.

[0244] In a struct socket, a struct sock must include at least the following:

[0245]

[0246] (3-2) Second socket

[0247] The second socket refers to the socket used for the second socket connection. In one example, the structure of the second socket is basically the same as that of the first socket. For example, the second socket also includes struct file, struct sock, struct socket_wq, and socket_state. Furthermore, the struct sock in the second socket also includes struct socket, socket_wq, kuid_t sk_uid, char sk_process_name[TASK_NAME_LEN], and possible_net_tskc_net.

[0248] (3-3) Exchange network connection information between the first socket and the second socket

[0249] In this embodiment, the network connection information to be exchanged between the first socket and the second socket includes the following contents (a) to (d).

[0250] (a) Swap the sock objects in the first and second sockets, see [link / reference] Figure 14 As shown.

[0251] It should be noted that `sock` is the connection entity for a socket and is the primary object for data exchange. For details, see [link to documentation]. Figure 15 As shown, the operating system swaps the sock objects by exchanging the struct sock*sk of the first and second sockets.

[0252] For ease of description, the `struct socket` of the first socket will be represented as `struct socket1`, which originally mapped to `struct sock1`. Similarly, the `struct socket` of the second socket will be represented as `struct socket2`, which originally mapped to `struct sock2`. After the `struct sock*sk` is swapped, there will be a remapping between `struct socket` and `struct sock` in the first and second sockets, as well as between the wait queue pointers. Specifically, as shown below:

[0253] For struct socket:

[0254] The struct sock*sk in the struct socket1 of the first socket no longer maps to struct sock1, but instead remaps to struct sock2.

[0255] The struct sock*sk in the second socket's struct socket2 no longer maps to struct sock2, but instead remaps to struct sock1.

[0256] Here, struct sock*sk is a pointer to sock in struct socket.

[0257] For struct sock:

[0258] The struct socket* sk_socket in the struct sock1 of the first socket no longer maps to struct socket1, but instead remaps to struct socket2.

[0259] The struct socket* sk_socket in the struct sock2 of the second socket no longer maps to struct socket2, but instead remaps to struct socket1.

[0260] Here, struct socket* sk_socket is a pointer in struct sock to struct socket.

[0261] For the waiting queue pointer:

[0262] The socket_wq*wq in struct sock1 no longer maps to struct sock*sk in struct socket1 of the first socket, but instead remaps to struct sock*sk in struct socket2 of the second socket.

[0263] The socket_wq*wq in struct sock2 no longer maps to struct sock*sk in struct socket2 of the second socket, but instead remaps to struct sock*sk in struct socket1 of the first socket.

[0264] It should be noted that swapping the pointers to the wait queue ensures that the user's original socket handle's select / poll interface will not encounter errors.

[0265] (b) Swap the file associated with the socket object. The file is associated with the socket and is a direct association with the user's socket handle, so this part needs to be swapped to keep the application unchanged.

[0266] (c) Swap the socket-state in struct socket1 of the first socket and struct socket2 of the second socket. It should be noted that swapping the socket-state ensures that the current state of the socket (e.g., unallocated, connected, disconnected, etc.) remains unchanged.

[0267] (d) Swap the `kuid_tsk_uid`, `char sk_process_name[TASK_NAME_LEN]`, and `possible_net_t skc_net` in `struct sock1` of the first socket and `struct sock2` of the second socket. This swaps the user ID, process name, and network namespace (such as network interface card information). It should be noted that this swapping process ensures that after swapping `struct sock1` of the first socket and `struct sock2` of the second socket, both the first and second sockets retain their original user ID, process name, and network namespace, preventing application process errors.

[0268] Scenario 2: The first network connection is a connection.

[0269] In this embodiment, the connection is a wrapper around a socket connection, and the application process can directly call the connection interface to initiate a connection. The connection interface still relies on the socket connection at its core.

[0270] Figure 16 This is a schematic diagram illustrating the application establishing a connection according to an embodiment of this application. See below for details.

[0271] First, the application creates a connection-id and initiates a connection by calling the connection interface based on the connection-id.

[0272] Subsequently, the connection interface initiates a system call to create the first socket and initiate a connection based on the first socket. The first socket corresponds to the first socket-id.

[0273] Next, the operating system searches for a second socket connection in the socket connection pool based on the socket triplet in the initiated connection. This socket connection pool can be a user-space socket connection pool or a kernel-space socket connection pool. The second socket connection uses a second socket, which corresponds to a second socket-id.

[0274] Finally, the operating system replaces the first socket in the connection with the second socket in the second socket connection, thereby establishing the first network connection. For example, see... Figure 17 As shown, the operating system replaces the first socket-id corresponding to the HTTP connection with the second socket-id of the second socket connection while keeping the connection-id unchanged, thereby establishing a connection.

[0275] It should be noted that in this embodiment, the operating system replaces the first socket-id corresponding to the HTTP connection with the second socket-id. This is equivalent to the connection being changed at the underlying level to call the second socket connection for communication, which can quickly establish a connection.

[0276] Scenario 3: The first network connection is an HTTP connection.

[0277] In this embodiment, the HTTP connection is a wrapper around the socket connection, and the application process can directly call the HTTP interface to initiate a connection. The HTTP interface still relies on the socket connection at the underlying level.

[0278] Figure 18 This is a schematic diagram illustrating the establishment of an HTTP connection by an application according to an embodiment of this application. The details are shown below.

[0279] First, the application creates an http-id and initiates an HTTP connection by calling the HTTP interface based on the http-id.

[0280] Subsequently, the HTTP interface initiates a system call to create the first socket and then initiates an HTTP connection based on the first socket. The first socket corresponds to the first socket-id.

[0281] Next, the operating system searches for a second socket connection in the socket connection pool based on the socket triplet in the initiated HTTP connection. This socket connection pool can be a user-space socket connection pool or a kernel-space socket connection pool. This second socket connection uses a second socket, which corresponds to a second socket-id.

[0282] Finally, the operating system replaces the first socket in the HTTP connection with the second socket in the second socket connection, thereby establishing the HTTP connection. For an example, see [link to example]. Figure 19 As shown, the operating system can replace the first socket-id corresponding to the HTTP connection with the second socket-id of the second socket connection while keeping the HTTP-id unchanged, thereby establishing an HTTP connection.

[0283] It should be noted that in this embodiment, the operating system replaces the first socket-id corresponding to the HTTP connection with the second socket-id. This is equivalent to the HTTP connection being changed at the underlying level to call the second socket connection for communication, which can quickly establish an HTTP connection.

[0284] Furthermore, the socket switching / replacement in scenarios 1 through 3 above is typically performed in kernel mode. However, in some embodiments, if the operating system's socket protocol stack has been completely migrated to user mode, then the aforementioned socket switching / replacement needs to be performed in user mode.

[0285] Part Four: Link Management

[0286] In this embodiment, the management of socket connections by the electronic device includes link lifecycle management, link keep-alive, link multiplexing, and link recycling. Details are as follows.

[0287] [Link Keep Alive]

[0288] For socket connections pre-established in the socket connection pool, a keep-alive period is usually configured. Before being used or deleted by the operating system, keep-alive data packets need to be sent using the socket connection according to the keep-alive period to keep the link alive.

[0289] Link lifecycle management

[0290] For pre-established socket connections in the socket connection pool, there may be instances where prediction fails. That is, due to prediction errors, the electronic device does not initiate the corresponding network connection, resulting in the pre-established socket connection remaining idle. Therefore, the socket connection pool needs to manage the lifecycle of idle sockets within the pool.

[0291] In some embodiments, if a third socket connection is not used within a preset time (e.g., 10 seconds, 30 seconds) after it is successfully established, the third socket connection is disconnected and removed from the socket connection pool.

[0292] In other embodiments, the network prediction module can also learn the usage of socket connections in the connection pool by application processes under different scenarios, and manage the socket connections in the connection pool based on this usage. For example, the network prediction module can learn the time interval T between the successful establishment of a socket connection and its use under different scenarios. If a socket connection is not used within time T after its establishment, the socket connection is cleared and the prediction algorithm is corrected.

[0293] Link reuse

[0294] Electronic devices can also reuse existing socket connections, improving link reuse rate and avoiding the need for dedicated resources to pre-establish socket connections, thus saving power consumption. Furthermore, improving link reuse rate reduces the impact of frequent connection establishment on the server, thereby reducing server resource consumption.

[0295] In some embodiments, applications that are frequently used by users may be reopened after a preset time period following their closure. Based on this, electronic devices can place the socket connections (e.g., third-party socket connections) that the application originally used in the application into a socket connection pool after the application is closed, so that the connection is prioritized when the application is reopened.

[0296] In other embodiments, some applications may request to re-establish a socket connection after releasing it. Therefore, for a socket connection that an application is preparing to release (e.g., a fourth socket connection), the electronic device can place it in a socket connection pool and delay releasing the fourth socket connection so that the application can use it when re-establishing the socket connection.

[0297] In some other embodiments, depending on business needs, some applications initiate two socket connections based on the same server device, such as a fifth socket connection and a sixth socket connection, and prioritize using the fifth socket connection that was established first. In this case, after the sixth socket connection is successfully established, the application typically releases the subsequently established sixth socket connection. Therefore, the electronic device can place the sixth socket connection in a socket connection pool for subsequent use by the application.

[0298] In some other embodiments, for socket connections that have been returned to the socket connection pool after the application process call ends, the release can be delayed for a preset time (e.g., 5 seconds, 10 seconds) to ensure that the application reuses the connection first when rebuilding the connection.

[0299] In some other embodiments, the electronic device can learn when the electronic device or server disconnects the socket connection, and store the socket connection in the socket connection pool and initiate keep-alive within a preset time (e.g., 3 seconds) before disconnecting the socket connection, for later use.

[0300] Link recycling

[0301] In some other embodiments, if a socket connection in the socket connection pool is detected to have not sent data for more than a preset time, and the network prediction module determines that link keep-alive is not required, the socket connection is automatically released and reclaimed. This method can save network resources for electronic devices and servers.

[0302] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.

[0303] This application also provides an electronic device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the methods for establishing network connections shown in the above embodiments.

[0304] This application also provides a chip, see [link to relevant documentation] Figure 20 As shown, the chip includes a processor and a memory, in which a computer program is stored. When the computer program is executed by the processor, it implements the methods for establishing network connections in the above embodiments.

[0305] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the methods for establishing network connections provided in the above embodiments.

[0306] This application also provides a computer program product, which includes a computer program that, when run by an electronic device, enables the electronic device to implement the methods for establishing network connections provided in the above embodiments.

[0307] It should be understood that the processor mentioned in the embodiments of this application can be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor can be a microprocessor or any conventional processor.

[0308] It should also be understood that the memory mentioned in the embodiments of this application can be volatile memory or non-volatile memory, or may include both volatile and non-volatile memory. The non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. The volatile memory can be random access memory (RAM), which is used as an external cache. By way of example, but not limitation, many forms of RAM are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous linked dynamic random access memory (SLDRAM), and direct rambus RAM (DR RAM).

[0309] In the embodiments provided in this application, the division of each framework or module is only a logical functional division. In actual implementation, there may be other division methods. For example, multiple frameworks or modules may be combined or integrated into another system, or some features may be ignored or not executed.

[0310] Furthermore, the functional modules in the various embodiments of this application can be integrated into one processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The integrated modules described above can be implemented in hardware or as software functional modules.

[0311] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0312] References to "one embodiment" or "some embodiments" as described in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.

[0313] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.

Claims

1. A method for establishing a network connection, characterized in that, Applied to electronic devices, the method includes: In response to the application initiating a first network connection based on a first socket, a second socket connection is searched in the socket connection pool based on the first socket; wherein the second socket connection includes a second socket, and the second socket has the same destination IP address, destination port, and transport protocol as the first socket; The first network connection is established by replacing the first socket in the first network connection with the second socket in the second socket connection.

2. The method according to claim 1, characterized in that, The step of replacing the first socket in the first network connection with the second socket to establish the first network connection includes: When the first network connection is a first socket connection, the network connection information in the first socket is replaced with the network connection information in the second socket, or the network connection information in the first socket and the second socket are swapped, thereby establishing the first socket connection.

3. The method according to claim 2, characterized in that, The method further includes: releasing the second socket connection.

4. The method according to claim 2 or 3, characterized in that, The network connection information includes: the socket-associated sock object, the socket-associated file, the current state of the socket, a pointer to the socket's waiting signal queue, and the user identifier (UID), process name, and network interface card information in the sock object.

5. The method according to claim 1, characterized in that, The step of replacing the first socket in the first network connection with the second socket in the second socket connection, thereby establishing the first network connection, includes: When the first network connection is a connection, the first socket-id in the connection is replaced with the second socket-id, thereby establishing the connection; When the first network connection is an HTTP connection, the second socket-id is used to replace the first socket-id in the first socket connection, thereby establishing the HTTP connection. Wherein, the first socket-id is the identification information of the first socket, and the second socket-id is the identification information of the second socket.

6. The method according to any one of claims 1 to 5, characterized in that, Before the application initiates the first network connection based on the first socket, the method further includes: In response to the first event, the basic network information of the pre-built chain is determined, including the destination domain name, destination port, and transmission protocol; Perform a Domain Name System (DNS) query based on the destination domain name to determine the destination Internet Protocol (IP) address; The second socket is created based on the destination IP address, the destination port, and the transport protocol; Establish the second socket connection based on the second socket; The second socket connection is stored in the socket connection pool.

7. The method according to claim 6, characterized in that, The first event includes: The application calls the network interface; Received a network task notification from the application; The artificial intelligence (AI) model predicts that a pre-built chain is needed. User actions, application events, or network events used to trigger network warm-up; The target text information was identified in the display interface / calendar information / electronic alarm clock; Receive notification information from the server or surrounding electronic devices regarding scheduled network tasks.

8. The method according to claim 6 or 7, characterized in that, The response to the first event, determining the basic network information of the pre-built chain, includes: In response to the first event, the basic network information is read locally, which is pre-configured in the electronic device; or, the basic network information is predicted by an AI model.

9. The method according to any one of claims 1 to 8, characterized in that, The socket connection pool includes a user-mode socket connection pool and a kernel-mode socket connection pool.

10. The method according to any one of claims 1 to 9, characterized in that, The second socket connection is either an established or being established socket connection.

11. The method according to any one of claims 1 to 10, characterized in that, The socket connection pool also includes a third socket connection, and the method further includes: After the third socket connection is successfully established, if the third socket connection is not used by the electronic device to transmit application data within a preset time, the third socket connection is disconnected and deleted from the socket connection pool.

12. The method according to any one of claims 1 to 11, characterized in that, The method further includes: If the application is preparing to release the fourth socket connection, before releasing the fourth socket connection, the fourth socket connection is recycled back to the socket connection pool, and the fourth socket connection is released after a preset time delay.

13. An electronic device, characterized in that, The method includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements the method as described in any one of claims 1 to 12.

14. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the method as described in any one of claims 1 to 12.

15. A chip, characterized in that, The chip includes a processor and a memory, the memory storing a computer program that, when executed by the processor, implements the method as described in any one of claims 1 to 12.

16. A computer program product, characterized in that, The computer program product includes a computer program that, when executed by a processor, implements the method as described in any one of claims 1 to 12.