Data access method, device, electronic device and storage medium
By obtaining the network cache data in the client to determine the switch identification of the transmission address, and selecting the appropriate target transmission address for data access, the problem of poor access to the server in IPv4 and IPv6 dual-stack modes is solved and more efficient access is achieved. Server side method.
Patent Information
- Application Number
- CN202411073245.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-06
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2044-08-06
AI Technical Summary
In the existing technology, IPv4 and IPv6 are allocated using the system's default dynamic allocation mechanism, which results in poor efficiency in accessing the server when the network satisfies the IPv4 and IPv6 dual-stack mode, especially when the IPv6 link is blocked or the IPv6 address is blocked. When access fails, the access speed of the interface may slow down or time out, and the server cannot be accessed.
By obtaining the network cache data in the client, the switch identification of the transmission address is determined, and based on the switch identification and access request, the appropriate target transmission address is selected for data access, thereby optimizing the protocol address of the access server and improving access efficiency.
By screening and judging and selecting the appropriate protocol for access connection, the efficiency of accessing the server is improved, access problems when the IPv6 link is blocked or failed are avoided, and fault tolerance is enhanced.
Smart Images

Figure CN118590871B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of mobile communications, and in particular to a data access method, device, electronic device and storage medium. Background Art
[0002] Due to the exhaustion of current IPv4 resources, the allocable IPv4 address space has been exhausted, and IPv6 access needs to be completed as soon as possible. At the same time, IPv6 has better security, transmission speed and configuration. As the network supports IPv4 and IPv6 dual stack mode, the software and hardware systems must also be upgraded to support the ability to access both IPv4 and IPv6.
[0003] In the prior art, when implementing the allocation of IPv4 and IPv6, the system default dynamic allocation mechanism is adopted, which cannot be refined to the IP control, resulting in the following situation: when the network meets the IPv4 and IPv6 dual stack mode, and the server host address also has an IPv6 address, IPv6 will be used for access first. At this time, if the link support of IPv6 is blocked, the access speed of the interface will be slowed down or timeout will occur; at the same time, when the access using the IPv6 address fails, the server will be inaccessible. The above situations will all lead to poor efficiency in accessing the server.
[0004] With regard to the problem of poor efficiency in accessing the server in the related art, no effective solution has been proposed yet. Summary of the invention
[0005] In this embodiment, a data access method, device, electronic device and storage medium are provided to solve the problem of poor efficiency in accessing a server in the related art.
[0006] In a first aspect, a data access method is provided in this embodiment, which is applied to a client, and the method includes:
[0007] Acquire network cache data of the client, and determine a switch identifier of a transmission address according to the network cache data; the transmission address is used for data access between the client and the server;
[0008] Obtaining a network data access request, and determining a target transmission address for accessing a server according to the network data access request and the switch identifier;
[0009] The server is accessed network data according to the target transmission address.
[0010] In some of the embodiments, the transmission address includes: a first transmission address, a second transmission address, and a third transmission address;
[0011] The step of obtaining the network cache data of the client and determining the identification switch of the transmission address according to the network cache data includes:
[0012] Acquire network cache data of an application in a client, and determine whether a first switch identifier of the first transmission address exists according to the network cache data;
[0013] When the first switch identifier of the first transmission address exists in the network cache data, an application access request is sent to the server according to the first switch identifier of the first transmission address.
[0014] In some embodiments, determining whether there is a first switch identifier of the first transmission address according to the network cache data includes:
[0015] When the first switch identifier of the first transmission address does not exist in the network cache data, calling the application program interface of the server and obtaining a second switch identifier pre-configured by the server;
[0016] The second switch identifier is used as the first switch identifier, and an application access request is sent to the server.
[0017] In some embodiments, determining a target transmission address for accessing a server according to the network data access request and the switch identifier includes:
[0018] When the network data access request carries the third transmission address, the network data access request is encapsulated into an interface class; an interceptor is provided on the interface class;
[0019] The network data access request is intercepted according to the interceptor to obtain the interface address of the network data access request;
[0020] Parsing the interface address to obtain the domain name of the server, and determining an address array corresponding to the third transmission address according to the domain name; the address array includes the first transmission address and the second transmission address;
[0021] A target transmission address is determined according to the address array and the switch identifier.
[0022] In some embodiments, determining the target transmission address according to the network data access request and the switch identifier includes:
[0023] Determine a target address in the address array according to the switch identifier;
[0024] The third transmission address is replaced by the target address to obtain the target transmission address.
[0025] In some embodiments, the method further comprises:
[0026] When the transmission address includes a first transmission address and a second transmission address, determining whether a first switch flag of the first transmission address of the client is turned on;
[0027] If the first switch flag is not turned on, the second transmission address is determined to be the target transmission address, and the server is accessed according to the second transmission address.
[0028] In some embodiments, determining whether the first switch flag of the first transmission address of the client is turned on includes:
[0029] If the first switch identifier is turned on, establishing an access connection to the server through the first switch identifier according to a preset socket;
[0030] When the socket does not return a response indicating that the access connection is successfully established within a preset time threshold, the second transmission address is determined to be the target transmission address, and the server is accessed according to the second transmission address.
[0031] In a second aspect, a data access device is provided in this embodiment, the device comprising: a switch identification acquisition module, a transmission address determination module, and a data access module;
[0032] The switch identifier acquisition module is used to acquire the network cache data of the client and determine the switch identifier of the transmission address according to the network cache data; the transmission address is a standard for data access between the client and the server;
[0033] The transmission address determination module is used to obtain a network data access request and determine a target transmission address for accessing the server according to the network data access request and the switch identifier;
[0034] The data access module is used to access data from the server according to the target transmission address.
[0035] In a third aspect, an electronic device is provided in this embodiment, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the data access method described in the first aspect when executing the computer program.
[0036] In a fourth aspect, a storage medium is provided in this embodiment, on which a computer program is stored, and when the program is executed by a processor, the data access method described in the first aspect is implemented.
[0037] Compared with the related art, the data access method, device, electronic device and storage medium provided in this embodiment determine the switch identifier through the cache data in the client, and determine the target transmission address of the client accessing the server according to the switch identifier and the access request of the client, and perform data access to the server according to the target transmission address. Through the above method, the protocol address of the access server is screened and judged, which is conducive to selecting the appropriate protocol for access connection, and is conducive to improving the efficiency of accessing the server.
[0038] Details of one or more embodiments of the present application are set forth in the following drawings and description to make other features, objects, and advantages of the present application more readily apparent. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0040] Figure 1 It is a hardware structure block diagram of a terminal of the data access method provided in an embodiment of the present application;
[0041] Figure 2 is a flow chart of a data access method provided by an embodiment of the present application;
[0042] Figure 3 This is a flowchart of obtaining an IPv6 switch identifier provided in this specific embodiment;
[0043] Figure 4 This is a flowchart of obtaining an IPv6 switch identifier provided in this specific embodiment;
[0044] Figure 5 This is a flowchart of obtaining an IPv6 switch identifier provided in this specific embodiment;
[0045] Figure 6 It is a structural block diagram of the data access device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0046] In order to more clearly understand the purpose, technical solutions and advantages of the present application, the present application is described and illustrated below in conjunction with the accompanying drawings and embodiments.
[0047] Unless otherwise defined, the technical terms or scientific terms involved in this application shall have the general meaning understood by people with general skills in the technical field to which this application belongs. The words "one", "a", "the", "these" and the like in this application do not indicate a quantitative limitation, and they may be singular or plural. The terms "include", "comprise", "have" and any variants thereof involved in this application are intended to cover non-exclusive inclusions; for example, a process, method and system, product or device comprising a series of steps or modules (units) is not limited to the listed steps or modules (units), but may include unlisted steps or modules (units), or may include other steps or modules (units) inherent to these processes, methods, products or devices. The words "connect", "connected", "coupled" and the like involved in this application are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. The "multiple" involved in this application refers to two or more. "And / or" describes the association relationship of associated objects, indicating that there may be three relationships, for example, "A and / or B" may mean: A exists alone, A and B exist at the same time, and B exists alone. Generally, the character " / " indicates that the objects associated with each other are in an "or" relationship. The terms "first", "second", "third", etc. in this application are only used to distinguish similar objects and do not represent a specific ordering of the objects.
[0048] The method embodiment provided in this embodiment can be executed in a terminal, a computer or a similar computing device. For example, running on a terminal, Figure 1 is a hardware structure block diagram of a terminal of the data access method provided in the embodiment of the present application. Figure 1 As shown, the terminal may include one or more ( Figure 1 Only one is shown in the figure) a processor 102 and a memory 104 for storing data, wherein the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA. The above terminal may also include a transmission device 106 and an input and output device 108 for communication functions. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above terminal. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations shown.
[0049] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the data access method in this embodiment. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, to implement the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0050] The transmission device 106 is used to receive or send data via a network. The above network includes a wireless network provided by a communication provider of the terminal. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (Radio Frequency, referred to as RF) module, which is used to communicate with the Internet wirelessly.
[0051] IPv4 (Internet Protocol version 4) is the fourth revision of the Internet Protocol in the development process and the first widely deployed version of this protocol. IPv6 (Internet Protocol Version 6), also known as IPng (IP Next Generation), provides connectionless data transmission services at the network layer. IPv6 is a set of specifications designed by IETF (Internet Engineering Task Force) and is an upgraded version of IPv4. Currently, in the field of mobile application development technology, the allocatable IPv4 address space has been exhausted, so IPv6 access needs to be completed as soon as possible.
[0052] In different systems, such as Android and IOS, as the network supports IPv4 and IPv6 dual-stack mode, the hardware and software systems must also be upgraded to support IPv4 and IPv6 access at the same time. Furthermore, Android system version 4.2 began to support IPv6 access, but when the server address of the access interface is the host IP address, it is necessary to consider whether the current network supports IPv6, whether there is a response and timeout when accessing the IPv6 address, etc. At the same time, the Android system supports IPv6 mode access for the underlying logic of the system, and it is difficult to expand the relevant API and refine the control granularity of the IP type. For the above two situations, it is necessary to design a method for detecting IP address type selection and IP address connectivity, and customize a set of IP address allocation rules. When accessing the interface, bypass the original Android system's dynamic IP address allocation mechanism and use the previously customized IP allocation mechanism. In this way, the Android software application can dynamically select the IP address type and switch between IPv4 and IPv6, which can be more convenient to expand, and at the same time have better fault tolerance, which can effectively improve the concentration of IPv6.
[0053] At present, the known methods for IPv6 transformation of Android systems use the default dynamic allocation mechanism of the Android system when dealing with the allocation of IPv4 and IPv6, and cannot be refined to the control of IP. In this way, the following two situations will occur. One of them is that when the domain name address is used to access the server, the current network meets the dual-stack mode of IPv4 and IPv6, and the server host address also has an IPv6 address, IPv6 will be used for access first. If there is a congestion problem in the link support of IPv6, the access speed of the interface will be slowed down or timeout will occur. When this problem occurs in the APP released online, the user will be greatly affected, and generally it is impossible to quickly optimize and solve such problems. In another case, when the server has multiple IP addresses of IPv4 and IPv6, and the IP address group is returned through the interface of the access management platform, it is impossible to know whether IPv4 or IPv6 is used for secondary interface access. For example, when the video stream IP address group of another server is obtained by accessing the interface address of the management platform, there may be multiple IPv4 and IPv6 addresses at this time. This cannot be judged using the underlying IP allocation mechanism of the Android system. It is up to the developer to judge and choose. If IPv6 is selected, problems may result in an inability to access server data, greatly increasing the difficulty of APP adaptation to IPv6.
[0054] In this embodiment, a data access method is provided. When requesting the APP network interface at multiple levels, local and global control is performed on whether the IPv6 mode is supported. The selection method when the server address is a domain name and an IP address is uniformly handled, which satisfies the APP's dynamic support for the IPv6 mode and improves the APP's fault tolerance. The access connection problem of the system mobile application when supporting the IPv4 and IPv6 dual stack modes is solved, the selection and control of the IP address type are improved, and when the server address is a domain name address, the selection of the IP address corresponding to the server domain name can be controlled at the APP code layer; at the same time, when the server address has two host IP addresses, IPv4 and IPv6, the appropriate IPv6 address is selected for access. When access using the IPv6 address fails, it has the ability to fall back to the IPv4 address.
[0055] Figure 2 is a flow chart of a data access method provided in an embodiment of the present application, such as Figure 2 As shown, the process is applied in the client, including the following steps S210 to S230.
[0056] Step S210, obtaining the network cache data of the client, and determining the switch identifier of the transmission address according to the network cache data; the transmission address is used for data access between the client and the server.
[0057] Among them, when the user starts the application, the client obtains the internal network cache data. The network cache data is a part of the data pre-loaded into the memory or storage of the device where the application device is located when the application is started for the first time or under specific conditions, including: static resources required when the application is loaded, dynamic data with low frequency of change and identity authentication information, etc., which are not specifically limited here; further, the client here can be a terminal device used by the user, and the terminal device includes: mobile phones, tablets and other devices. After obtaining the network cache data, read the network cache data, and determine whether the network cache data includes a switch identifier for a pre-set transmission address. The transmission address here can specifically be an address including an IP address and an address including a domain name, which are not specifically limited here. The switch identifier includes operating system settings, router configuration, application file configuration, and application interface requests, etc.
[0058] Step S220, obtaining a network data access request, and determining a target transmission address for accessing the server according to the network data access request and the switch identifier.
[0059] The client receives a network data access request initiated by a user, and determines the target transmission address of the access server according to the network data access request and the switch identifier of the transmission address, wherein the target transmission address is successfully connected to the server and the client, and can be determined by using the allocation mechanism of the client system. For example, in the prior art, when the client system is an Android system, the target transmission address is determined by the default dynamic allocation mechanism of the Android system, while in this embodiment, the target transmission address is determined for different server addresses and the connection between the server and the client.
[0060] Step S230: Access network data to the server according to the target transmission address.
[0061] Among them, after the client determines the target transmission address connected to the server, it accesses network data to the server according to the target transmission address.
[0062] Through the above steps, the switch identifier is determined by the cache data in the client, and the target transmission address of the client accessing the server is determined according to the switch identifier and the access request of the client, and the server is accessed according to the target transmission address. Through the above method, the protocol address of the access server is judged, which is conducive to selecting a suitable protocol for access connection, and is conducive to improving the efficiency of accessing the server.
[0063] In some embodiments, the transmission address includes: a first transmission address, a second transmission address and a third transmission address. Specifically, the first transmission address includes an IPv6 address, the second transmission address includes an IPv4 address, and the third transmission address includes a domain name address.
[0064] In step S210, the network cache data of the client is obtained, and the identification switch of the transmission address is determined according to the network cache data, including steps S211 to S213.
[0065] Step S211: Acquire network cache data of an application program in the client, and determine whether there is a first switch identifier of a first transmission address according to the network cache data.
[0066] Among them, after obtaining the network cache data of the application in the client, it is determined whether there is a first switch identifier of the first transmission address in the network cache data, that is, it is determined whether the user pre-configures the first switch identifier of the first transmission address. The first switch identifier is manually set by the user in the client application, and a switch interface is provided. When the user turns on and off the first switch identifier of the first transmission address, the state of the first switch identifier does not change; when the user does not set the first switch identifier, it is determined that the first switch identifier is empty, and the switch identifier of the connection application configured by the management platform is determined through the management platform of the server.
[0067] Step S212: When the first switch identifier of the first transmission address exists in the network cache data, an application access request is sent to the server according to the first switch identifier of the first transmission address.
[0068] Among them, when it is determined that there is a first switch identifier of the first transmission address in the network cache data, an application access request is initiated to the server through the first switch identifier, that is, when there is a first switch identifier in the network cache data and the user sets to turn on the first switch identifier, the server is directly connected through the first switch identifier.
[0069] Step S213, when the first switch identifier of the first transmission address does not exist in the network cache data, call the application interface of the server and obtain the second switch identifier pre-configured by the server; use the second switch identifier as the first switch identifier and send an application access request to the server.
[0070] Among them, when the first switch identifier of the first transmission address does not exist in the network cache data, an independent application interface is called on the management platform of the server to obtain the second switch identifier pre-configured on the management platform of the server, and then an application access request is sent to the server according to the second switch identifier.
[0071] Through the above steps, by determining whether the first switch identifier exists in the network cache data and using the first switch identifier for access, it is beneficial to directly access the application according to the state of the first switch identifier of the first transmission address, which is beneficial to avoid the situation where access through the first transmission address fails, and is beneficial to improve the accuracy and efficiency of the client's access to the server.
[0072] In some of the embodiments, in step S220, a target transmission address for accessing the server is determined according to the network data access request and the switch identifier, including steps S221 to S223.
[0073] Step S221, when the network data access request carries the third transmission address, the network data access request is encapsulated into an interface class; an interceptor is set on the interface class.
[0074] Among them, when the transmission address in the network data access request is the third transmission address, that is, the address for accessing the server is a domain name address, it is necessary to encapsulate the network data access request of the application initiated by the client, encapsulate the exit of all requests on the same interface class of the application in the client, and set an interceptor on the interface class. Exemplarily, the interface class can be a service interface class, a data interface class, an application state interface class, a cache control interface class, etc., and an interceptor is set on the interface class, allowing functions such as logging, performance monitoring, transaction management, and security control to be added without changing the original business logic code. The interceptor method is not specifically limited here.
[0075] Step S222: intercept the network data access request according to the interceptor to obtain the interface address of the network data access request.
[0076] The client intercepts the initiated network data access request according to the interceptor, thereby obtaining the interface address carried in the request.
[0077] Step S223, the interface address is parsed to obtain the domain name of the server, and the address array corresponding to the third transmission address is determined according to the domain name; the address array includes the first transmission address and the second transmission address; the target transmission address is determined according to the address array and the switch identifier. Further, the target address in the address array is determined according to the switch identifier; the third transmission address is replaced by the target address to obtain the target transmission address.
[0078] Among them, the client resolves the interface address through a custom interface address resolver, and then obtains the corresponding host domain name of the server. The domain name of the server is used as a parameter to determine the address array corresponding to the domain name address, and the target transmission address is determined according to the address array and the switch identifier corresponding to the address. Exemplarily, according to the switch identifier of the client application, such as the first switch identifier in the aforementioned embodiment, one of the IP addresses in the address array is selected, and the original server address, that is, the third transmission address, is replaced according to the IP address, thereby forming a new target transmission address to initiate a request to the server.
[0079] Through the above steps, when the address of accessing the server is a domain name address, the client application parses the domain name address, that is, the interface request of the application is uniformly packaged and processed, and an interceptor is set. When the application initiates a network data access request, the interface address is intercepted and obtained, and the address array is determined according to the interface address, and the target transmission address is determined in combination with the switch identifier corresponding to the address of the application, which is conducive to avoiding the failure of accessing the server due to port errors or blacklists, and is conducive to improving the efficiency and accuracy of accessing the server.
[0080] In some embodiments, the method further includes: when the transmission address includes the first transmission address and the second transmission address, determining whether the first switch identifier of the first transmission address of the client is turned on; if the first switch identifier is not turned on, determining the second transmission address as the target transmission address, and accessing the server according to the second transmission address. If the first switch identifier is turned on, establishing an access connection to the server through the first switch identifier according to a preset socket.
[0081] Among them, when the accessed server supports both the first transmission address and the second transmission address, and the accessed network also satisfies the dual-stack mode of the two transmission addresses, it is necessary to first determine whether the first switch identifier of the first transmission address of the client application is turned on. If the first switch identifier is turned off, then the second transmission address is directly used to initiate a network data access request to the server. If the first switch identifier is turned on, then a socket is needed to establish a connection to the server through the first transmission address corresponding to the first switch identifier.
[0082] Further, when the socket does not return a response indicating successful establishment of the access connection within a preset time threshold, the second transmission address is determined to be the target transmission address, and the server is accessed according to the second transmission address.
[0083] Among them, when using the socket to establish a connection to the server through the first transmission address corresponding to the first switch identifier, it is necessary to set a connection time limit, that is, when the socket does not return a response signal of successful connection within the preset connection time, it is determined that the first transmission address cannot be used to access the server. At this time, the server is directly accessed through the second transmission address.
[0084] Through the above steps, when the accessed server supports and the accessed network also supports the first transmission address and the second transmission address, it is determined whether the second transmission address should be used to establish an access connection with the server based on the on / off status of the first switch identifier of the first transmission address and the connection status of the first transmission address. This helps avoid falling back to the second transmission address mode for access when the first transmission address cannot access the server, increases the fault tolerance capability of supporting the first transmission address, helps avoid failures in accessing the server, and helps improve the efficiency of accessing the server.
[0085] The present embodiment is described and illustrated by means of specific examples below.
[0086] This embodiment also provides a method for supporting IPv6 access in an Android system. Figure 3 This is a flowchart of obtaining an IPv6 switch identifier provided in this specific embodiment. Figure 3As shown, the management platform of the server needs to configure the IPv6 identification switch. When the APP application, that is, the application program of the client in the aforementioned embodiment, is started, it will read whether the local cache has the IPv6 switch identification set by the user. The identification can provide a switch interface in the APP, which is manually set by the user, and has the highest priority, and is only effective for a single user's APP. Once the user turns off the identification of the IPv6 switch, the switch identification status of the IPv6 will not change except for clearing the cache of the APP or manually turning it on by the user. If the user has not set it, the switch identification is empty, that is, it is judged that there is no IPv6 switch identification set by the user in the local cache, then an independent interface request will be initiated to the management platform of the server, and the switch identification (parameters) configured by the management platform will be obtained by calling the independent API interface of the management platform. This setting is effective for the APP of some users online. If the IPv6 switch identification is successfully obtained and is in the on state, the APP initiates a network data access request to the server through the IPv6 address corresponding to the IPv6 switch identification. If the network and the server both support IPv4 and IPv6 dual stack mode in the future, the IPv6 address is used for access first, and if it fails, it falls back to IPv4. If the IPv6 switch identifier fails to be obtained or is empty, the IPv4 address is used uniformly to access the interface. The IPv6 address here is the first transmission address in the above embodiment, the IPv4 address here is the second transmission address in the above embodiment, and the IPv6 switch identifier here is the first switch identifier in the above embodiment.
[0087] If the address of the server accessed by the APP is a domain name address, the domain name needs to be resolved by DNS. Figure 4 This is a flowchart of obtaining an IPv6 switch identifier provided in this specific embodiment. Figure 4, here we take the Android application APP as an example. When the APP initiates a network data access request, the APP's interface request needs to be uniformly encapsulated, that is, all interface request exports are encapsulated into an interface Manager class, and an interceptor Interceptor is set in this class. When the APP initiates an interface request, it is intercepted on the Interceptor interceptor of the interface Manager class to obtain the interface address HttpUrl. Then, by customizing an interface address resolver HttpDNSParser, the interface address is parsed to obtain the server's host domain name. The obtained host domain name is used as a parameter, and the getAllByName() method of the InetAddress class of the Android system is called to obtain the IP address array corresponding to the domain name. The IP address array here includes IPv4 addresses and IPv6 addresses. At this time, one of the corresponding IP addresses is selected according to the switch flag of the APP, and the domain name of the original server address is replaced to form a new server IP address HttpUrl to request the server. Specifically, when the switch flag of the IPv6 address is turned on, the domain name of the original server address is replaced by the IPv6 address to form a new server IPv6 address HttpUrl, and the server is requested according to the new address; when the switch flag of the IPv6 address is not turned on, the domain name of the original server address is replaced by the IPv4 address to form a new server IPv4 address HttpUrl, and the server is requested according to the new address. Because the call is returned by the InetAddress class, the IP address here does not have the connection failure problem caused by port errors or blacklists.
[0088] If the server you are accessing supports both IPv4 and IPv6 addresses, and the network also meets the IPv4 and IPv6 dual stack mode, you need to determine whether the IPv6 switch flag of the APP is turned on. Figure 5 This is a flowchart of obtaining an IPv6 switch identifier provided in this specific embodiment. Figure 5There are two situations: 1. When the IPv6 switch flag is off, the IPv4 interface address is directly used to initiate an interface request to the server for access. 2. When the IPv6 switch flag is on, the Socket socket needs to be used to establish a connection to the server using the IPv6 address in the IP address array, and a timeout limit of 200ms is set. If the Socket does not return a successful connection response within the set time or the Socket fails to establish a connection, it is determined that the IPv6 address is timed out or the connection is unavailable, and it should fall back to the IPv4 interface address and use the IPv4 interface address to initiate an interface request to the server for access. If the Socket returns a successful connection response within the set time, an interface request is initiated to the server using the IPv6 interface address for access.
[0089] This embodiment makes local and global control on whether to support IPv6 mode when requesting APP network interface at multiple levels, unifies the selection method when the server address is a domain name and an IP address, satisfies APP to dynamically support IPv6 mode, and improves the fault tolerance of APP. Specifically, the user manually sets the IPv6 switch flag, and the management platform of the server configures the IPv6 switch flag, which limits the scope to be effective for a single user's APP and for all users' APPs. For the version released online, it can be selected by the user or configured by the platform to take effect, avoiding the risk of being unable to fall back when IPv6 fails, so as to realize the selection and control of IPv6 mode. When the server address is a domain name address, the APP request interface is intercepted, and the InetAddress class that comes with the Android system is used to obtain the IP array, and then dynamically selected according to the IPv6 switch flag, and the new HttpUrl interface containing the IP address is reassembled, so that the IP address can be dynamically selected, which effectively reduces the balanced load of the server. When the server address is an IP address, a socket is used to establish a connection to determine whether IPv6 is available, and a timeout is set to determine whether the current network environment and server meet the IPv6 mode. If not, the IPv4 mode is used.
[0090] In this embodiment, a data access device is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. The terms "module", "unit", "subunit" and the like used below can implement a combination of software and / or hardware of predetermined functions. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware is also possible and conceivable.
[0091] Figure 6 is a structural block diagram of a data access device provided in an embodiment of the present application, such as Figure 6 As shown, the device includes: a switch identification acquisition module 10, a transmission address determination module 20, and a data access module 30.
[0092] The switch identifier acquisition module 10 is used to acquire the network cache data of the client and determine the switch identifier of the transmission address according to the network cache data; the transmission address is a standard for data access between the client and the server.
[0093] The transmission address determination module 20 is used to obtain a network data access request and determine a target transmission address for accessing the server according to the network data access request and the switch identifier.
[0094] The data access module 30 is used to access data from the server according to the target transmission address.
[0095] It should be noted that the above modules can be functional modules or program modules, and can be implemented by software or hardware. For modules implemented by hardware, the above modules can be located in the same processor; or the above modules can be located in different processors in any combination.
[0096] In this embodiment, an electronic device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0097] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0098] Optionally, in this embodiment, the processor may be configured to perform the following steps through a computer program:
[0099] S1, obtaining the network cache data of the client, and determining the switch identifier of the transmission address according to the network cache data; the transmission address is the standard for data access between the client and the server.
[0100] S2, obtaining a network data access request, and determining a target transmission address for accessing the server according to the network data access request and the switch identifier.
[0101] S3, access network data from the server according to the target transmission address.
[0102] It should be noted that the specific examples in this embodiment can refer to the examples described in the above embodiments and optional implementation modes, and will not be repeated in this embodiment.
[0103] In addition, in combination with the data access method provided in the above embodiments, a storage medium may be provided in this embodiment to implement the data access method. The storage medium stores a computer program, and when the computer program is executed by a processor, any one of the data access methods in the above embodiments is implemented.
[0104] It should be understood that the specific embodiments described herein are only used to explain the application, rather than to limit it. Based on the embodiments provided in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the protection scope of this application.
[0105] Obviously, the drawings are only some examples or embodiments of the present application. For ordinary technicians in the field, the present application can also be applied to other similar situations based on these drawings without creative work. In addition, it is understandable that although the work done in this development process may be complicated and lengthy, for ordinary technicians in the field, certain changes in design, manufacturing or production based on the technical content disclosed in this application are only conventional technical means and should not be regarded as insufficient content disclosed in this application.
[0106] The term "embodiment" in this application refers to a specific feature, structure or characteristic described in conjunction with the embodiment that can be included in at least one embodiment of the present application. The appearance of this phrase in various locations in the specification does not necessarily mean the same embodiment, nor does it mean that it is mutually exclusive with other embodiments and is independent or optional. It is clearly or implicitly understood by those of ordinary skill in the art that the embodiments described in this application can be combined with other embodiments without conflict.
[0107] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of patent protection. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the scope of protection of the present application. Therefore, the scope of protection of the present application shall be subject to the attached claims.
Claims
1. A data access method, It is characterized in that Applied to a client, the method comprises: Acquire network cache data of the client, and determine a switch identifier of a transmission address according to the network cache data; the transmission address is used for data access between the client and the server; Obtaining a network data access request, and determining a target transmission address for accessing a service end according to the network data access request and the switch identifier; Performing network data access on the server according to the target transmission address; The step of obtaining the network cache data of the client and determining the identification switch of the transmission address according to the network cache data includes: Determine whether there is a first switch identifier of the first transmission address according to the network cache data; the transmission address includes the first transmission address; the first switch identifier is manually set by the user in the application of the client; When the first switch identifier of the first transmission address does not exist in the network cache data, the application program interface of the server is called, and the second switch identifier pre-configured by the server is obtained; the second switch identifier is used as the first switch identifier, and an application program access request is sent to the server.
2. The data access method according to claim 1, It is characterized in that The transmission address also includes: a second transmission address and a third transmission address; The step of obtaining the network cache data of the client and determining the identification switch of the transmission address according to the network cache data further includes: Acquire network cache data of an application in the client; when a first switch identifier of the first transmission address exists in the network cache data, send an application access request to the server according to the first switch identifier of the first transmission address.
3. The data access method according to claim 2, It is characterized in that The step of determining a target transmission address for accessing the server according to the network data access request and the switch identifier includes: When the network data access request carries the third transmission address, the network data access request is encapsulated into an interface class; an interceptor is provided on the interface class; The network data access request is intercepted according to the interceptor to obtain the interface address of the network data access request; Parsing the interface address to obtain the domain name of the server, and determining an address array corresponding to the third transmission address according to the domain name; the address array includes the first transmission address and the second transmission address; A target transmission address is determined according to the address array and the switch identifier.
4. The data access method according to claim 3, It is characterized in that The determining the target transmission address according to the network data access request and the switch identifier includes: Determine a target address in the address array according to the switch identifier; The third transmission address is replaced by the target address to obtain the target transmission address.
5. The data access method according to claim 2, It is characterized in that The method further comprises: When the transmission address includes a first transmission address and a second transmission address, determining whether a first switch flag of the first transmission address of the client is turned on; If the first switch flag is not turned on, the second transmission address is determined to be the target transmission address, and the server is accessed according to the second transmission address.
6. The data access method according to claim 5, It is characterized in that The determining whether the first switch flag of the first transmission address of the client is turned on includes: If the first switch identifier is turned on, establishing an access connection to the server through the first switch identifier according to a preset socket; When the socket does not return a response indicating that the access connection is successfully established within a preset time threshold, the second transmission address is determined to be the target transmission address, and the server is accessed according to the second transmission address.
7. A data access device, It is characterized in that The device comprises: a switch identification acquisition module, a transmission address determination module, and a data access module; The switch identification acquisition module is used to acquire the network cache data of the client, and determine the switch identification of the transmission address according to the network cache data; the transmission address is used for data access between the client and the server; the acquisition of the network cache data of the client, and determining the identification switch of the transmission address according to the network cache data, includes: determining whether there is a first switch identification of the first transmission address according to the network cache data; the transmission address includes the first transmission address; the first switch identification is manually set by the user in the application of the client; The transmission address determination module is used to obtain a network data access request, and determine a target transmission address for accessing the server according to the network data access request and the switch identifier; and is also used to call the application program interface of the server and obtain a second switch identifier pre-configured by the server when the first switch identifier of the first transmission address does not exist in the network cache data; and use the second switch identifier as the first switch identifier to send an application program access request to the server; The data access module is used to access data from the server according to the target transmission address.
8. An electronic device comprising a memory and a processor, It is characterized in that A computer program is stored in the memory, and the processor is configured to run the computer program to perform the data access method according to any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the steps of the data access method according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Load balancing method and system based on IPV6 mechanism
CN111770137A
