Communication method and apparatus
This application provides a communication method and an apparatus. The method includes: accessing, by an electronic device, a first network; performing network probing on the first network, where it is detected that the Internet cannot be accessed through the first network; and transmitting, in the first network and a second network, to-be-transmitted data through a network that matches the to-be-transmitted data, where the first network is different from the second network, and the electronic device can access the second network and maintain a connection to the first network. The Internet can be accessed through the second network. Even if the Internet cannot be accessed through the first network, the electronic device can still access the Internet through the second network, and is not disconnected from the first network, maintaining the capability of the first network to transmit data.
1 . A communication method, comprising:
accessing, by a first electronic device, a wireless local area network provided by a second electronic device, wherein the first electronic device cannot access the Internet through the wireless local area network provided by the second electronic device, and the first electronic device accesses the Internet through a cellular network;
generating, by the first electronic device, a data transmission request;
performing the following:
sending the data transmission request to the second electronic device through the wireless local area network in a case that a target address of the data transmission request is an address of the second electronic device; or
sending the data transmission request through the cellular network in a case that a target address of the data transmission request is not an address of the second electronic device;
in a case that a network parallel control setting of the first electronic device is disabled, in response to a first operation of a user, accessing, by the first electronic device, the cellular network, and breaking the connection to the wireless local area network; and
in a case that the network parallel control setting of the first electronic device is disabled, in response to a second operation of the user, accessing, by the first electronic device, the wireless local area network, and breaking a connection to the cellular network.
2 . The method according to claim 1 , further comprising:
displaying, based on the Internet cannot be accessed through the wireless local area network, a first interface, wherein the first interface comprises a first prompt information, and the first prompt information indicates whether to continue using the wireless local area network, and
displaying, when the user feeds back to continue using the wireless local area network, a second interface, wherein the second interface comprises a second prompt information, and the second prompt information whether to enable the network parallel control setting, and
receiving an operation of enabling the network parallel control setting.
3 . The method according to claim 1 , further comprising:
adding, in response to enabling of the network parallel control setting by the user, a routing rule of the wireless local area network to a routing rule of the first electronic device, wherein a priority of the routing rule of the wireless local area network is higher than a priority of a routing rule of the cellular network, and the routing rule of the wireless local area network comprises a condition for transmitting the data transmission request through the wireless local area network.
4 . The method according to claim 1 , wherein an identifier of a network device or an address of the network device is recorded in a routing rule of the wireless local area network, and the first electronic device sends the data transmission request to the second electronic device through the network device indicated by the identifier of the network device or the address of the network device.
5 . The method according to claim 1 , further comprising:
sending a probe request through the wireless local area network;
receiving a status code through the wireless local area network; and
in a case that the status code indicates that the Internet cannot be accessed through the wireless local area network, and the network parallel control setting of the first electronic device is enabled, accessing, by the first electronic device, the cellular network, and maintaining a connection to the wireless local area network.
6 . The method according to claim 5 , further comprising:
displaying, by the first electronic device in a case that the status code indicates that the Internet cannot be accessed through the wireless local area network, a prompt box;
determining, by the first electronic device in response to a third operation of a user, that the network parallel control setting is enabled; and
determining, by the first electronic device in response to a fourth operation of the user, that the network parallel control setting is disabled.
7 . The method according to claim 5 , further comprising:
searching, by the first electronic device in a case that the status code indicates that the Internet cannot be accessed through the wireless local area network, for a setting result of the network parallel control setting in a setting interface, wherein the setting result indicates that the network parallel control setting of the first electronic device is enabled or disabled.
8 . The method according to claim 1 , further comprising:
deleting a routing rule of the wireless local area network from a routing rule of the first electronic device in a case that the first electronic device breaks the connection to the wireless local area network; and
adding the routing rule of the wireless local area network to the routing rule of the first electronic device in a case that the first electronic device re-accesses the wireless local area network and the network parallel control setting is enabled.
9 . An electronic device, comprising:
a memory and a processor, wherein the memory stores instructions executable by the processor, and when the processor executes the instructions, the electronic device is caused to:
access a wireless local area network provided by a second electronic device, wherein the electronic device cannot access the Internet through the wireless local area network provided by the second electronic device, and the electronic device accesses the Internet through a cellular network;
generate a data transmission request;
perform the following:
send the data transmission request to the second electronic device through the wireless local area network in a case that a target address of the data transmission request is an address of the second electronic device; or
send the data transmission request through the cellular network in a case that a target address of the data transmission request is not an address of the second electronic device;
in a case that a network parallel control setting of the electronic device is disabled, in response to a first operation of a user, access the cellular network, and break the connection to the wireless local area network; and
in a case that the network parallel control setting of the electronic device is disabled, in response to a second operation of the user, access the wireless local area network, and break a connection to the cellular network.
10 . The electronic device according to claim 9 , wherein when the processor executes the instructions, the electronic device is further caused to:
display, based on the Internet cannot be accessed through the wireless local area network, a first interface, wherein the first interface comprises a first prompt information, and the first prompt information indicates whether to continue using the wireless local area network,
display when the user feeds back to continue using the wireless local area network, a second interface, wherein the second interface comprises a second prompt information, and the second prompt information whether to enable the network parallel control setting, and
receive an operation of enabling the network parallel control setting.
11 . The electronic device according to claim 9 , wherein when the processor executes the instructions, the electronic device is further caused to:
add, in response to enabling of the network parallel control setting by the user, a routing rule of the wireless local area network to a routing rule of the electronic device, wherein a priority of the routing rule of the wireless local area network is higher than a priority of a routing rule of the cellular network, and the routing rule of the wireless local area network comprises a condition for transmitting the data transmission request through the wireless local area network.
12 . The electronic device according to claim 9 , wherein an identifier of a network device or an address of the network device is recorded in a routing rule of the wireless local area network, and the electronic device sends the data transmission request to the second electronic device through the network device indicated by the identifier of the network device or the address of the network device.
13 . The electronic device according to claim 9 , wherein when the processor executes the instructions, the electronic device is further caused to:
send a probe request through the wireless local area network;
receive a status code through the wireless local area network; and
in a case that the status code indicates that the Internet cannot be accessed through the wireless local area network, and the network parallel control setting of the electronic device is enabled, access the cellular network, and maintain a connection to the wireless local area network.
14 . The electronic device according to claim 13 , wherein when the processor executes the instructions, the electronic device is further caused to:
display, in a case that the status code indicates that the Internet cannot be accessed through the wireless local area network, a prompt box;
determine, in response to a third operation of the user, that a network parallel control setting is enabled; and
determine, in response to a fourth operation of the user, that the network parallel control setting is disabled.
15 . The electronic device according to claim 13 , wherein when the processor executes the instructions, the electronic device is further caused to:
search, in a case that the status code indicates that the Internet cannot be accessed through the wireless local area network, for a setting result of the network parallel control setting in a setting interface, wherein the setting result indicates that the network parallel control setting of the electronic device is enabled or disabled.
16 . The electronic device according to claim 9 , wherein when the processor executes the instructions, the electronic device is further caused to:
delete a routing rule of the wireless local area network from a routing rule of the electronic device in a case that the electronic device breaks the connection to the wireless local area network; and
add the routing rule of the wireless local area network to the routing rule of the electronic device in a case that the electronic device re-accesses the wireless local area network and the network parallel control setting is enabled.
17 . A non-transitory computer-readable storage medium, storing a computer program, wherein the computer program, when run by a processor of an electronic device, causes the electronic device to:
access a wireless local area network provided by a second electronic device, wherein the electronic device cannot access the Internet through the wireless local area network provided by the second electronic device, and the electronic device accesses the Internet through a cellular network;
generate a data transmission request; and
perform the following:
send the data transmission request to the second electronic device through the wireless local area network in a case that a target address of the data transmission request is an address of the second electronic device; or
send the data transmission request through the cellular network in a case that a target address of the data transmission request is not an address of the second electronic device;
in a case that a network parallel control setting of the electronic device is disabled, in response to a first operation of a user, access the cellular network, and break the connection to the wireless local area network; and
in a case that the network parallel control setting of the electronic device is disabled, in response to a second operation of the user, access the wireless local area network, and break a connection to the cellular network.
18 . The non-transitory computer-readable storage medium according to claim 17 , wherein when the computer program is run by the processor of the electronic device, the computer program causes the electronic device to further:
display, based on the Internet cannot be accessed through the wireless local area network, a first interface, wherein the first interface comprises a first prompt information, and the first prompt information indicates whether to continue using the wireless local area network,
display when the user feeds back to continue using the wireless local area network, a second interface, wherein the second interface comprises a second prompt information, and the second prompt information whether to enable the network parallel control setting, and
receive an operation of enabling the network parallel control setting.
19 . The non-transitory computer-readable storage medium according to claim 17 , wherein when the computer program is run by the processor of the electronic device, the computer program causes the electronic device to further:
add, in response to enabling of the network parallel control setting by the user, a routing rule of the wireless local area network to a routing rule of the electronic device, wherein a priority of the routing rule of the wireless local area network is higher than a priority of a routing rule of the cellular network, and the routing rule of the wireless local area network comprises a condition for transmitting the data transmission request through the wireless local area network.
20 . The non-transitory computer-readable storage medium according to claim 17 , wherein an identifier of a network device or an address of the network device is recorded in a routing rule of the wireless local area network, and the electronic device sends the data transmission request to the second electronic device through the network device indicated by the identifier of the network device or the address of the network device.