Device communication method and electronic device

CN120769366BActive Publication Date: 2026-08-21HONOR DEVICE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410389511.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-03-30
Publication Date
2026-08-21
Estimated Expiration
2044-03-30

AI Technical Summary

Technical Problem

[0004]本发明实施例提供一种设备通信方法及电子设备,以解决用户在使用P2P连接时等待时间长的问题

Benefits of technology

[0128]应当理解的是,本申请的第二方面至第十方面与本申请的第一方面的技术方案相对应,各方面及对应的可能的实现所取得的有益效果相似,不再赘述。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120769366B_ABST
    Figure CN120769366B_ABST
Patent Text Reader

Abstract

Embodiments of the present application disclose a device communication method and an electronic device. In response to a user operation for sending first data to a second electronic device, a first electronic device initiates establishment of a wireless local area network (WLAN) connection and establishment of a point-to-point (P2P) connection with the second electronic device. After the WLAN connection is successfully established, the first electronic device transmits data through the WLAN connection before the P2P connection is successfully established. After the P2P connection is successfully established, the first electronic device transmits data through the P2P connection, so as to reduce the waiting time of the user and provide a user experience.
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 device communication method and an electronic device. Background Technology

[0002] When two devices in a Wireless Local Area Network (WLAN) communicate, they can use a WLAN connection or a peer-to-peer (P2P) connection for data transmission. In some scenarios, such as multi-screen collaboration between mobile phones and tablets, multi-screen collaboration between mobile phones and PCs, wireless screen mirroring between mobile phones and smart screens, or keyboard and mouse sharing services between multiple terminal devices, high-quality wireless links are required. Even if the devices are within the same local area network, a P2P connection is often necessary to ensure service quality and user experience.

[0003] Because establishing a P2P connection involves many steps and is time-consuming (more so than establishing a WLAN connection), users experience significant waiting time when using a P2P connection, resulting in a poor user experience. Summary of the Invention

[0004] This invention provides a device communication method and an electronic device to solve the problem of long waiting times when users use P2P connections.

[0005] In a first aspect, embodiments of this application provide a device communication method applied to a first electronic device, the method comprising:

[0006] In response to a received user operation to send first data to a second electronic device, the first electronic device initiates the establishment of a wireless local area network (WLAN) connection with the second electronic device and a point-to-point (P2P) connection with the second electronic device. The first electronic device and the second electronic device are respectively connected to the same wireless access point via WLAN.

[0007] After the first electronic device successfully establishes a WLAN connection with the second electronic device, but before the first electronic device successfully establishes a P2P connection with the second electronic device, it sends the first data to the second electronic device via the WLAN connection.

[0008] After the first electronic device successfully establishes a P2P connection with the second electronic device, it sends the first data to the second electronic device through the P2P connection.

[0009] In the above method, when the first electronic device initiates the sending of first data to the second electronic device, it simultaneously initiates the establishment of a WLAN connection and a P2P connection. After the WLAN connection is successfully established but before the P2P connection is successfully established, the data is transmitted first through the faster WLAN connection. After the P2P connection is successfully established, the data is transmitted through the P2P connection, thereby reducing the user's waiting time and improving the user experience.

[0010] It should be noted that the first electronic device is also called the first device or client, and the second electronic device is also called the second device or server. When the first electronic device initiates a data transmission request to the second electronic device, it simultaneously establishes a WLAN connection and a P2P connection. Here, "simultaneously" can mean that the establishment of the WLAN connection and the P2P connection are triggered or started at the same time, or that the establishment of the WLAN connection and the P2P connection are triggered or started at two very short intervals. For example, the first electronic device triggers or starts establishing the WLAN connection at the first time and triggers or starts establishing the P2P connection at the second time. The difference between the first time and the second time is less than 1 second, 0.5 seconds, or less.

[0011] In one possible implementation, the method further includes: after the first electronic device successfully establishes a WLAN connection, adding WLAN data path information to a first data path list, wherein the WLAN data path information includes the WLAN IP of the second electronic device and a first port, wherein the first port is the port of the WLAN IP of the second electronic device;

[0012] After the first electronic device successfully establishes a P2P connection, it adds the P2P data path information to the first data path list. The P2P data path information includes the P2P IP of the second electronic device and the second port, where the second port is the port of the P2P IP of the second electronic device.

[0013] It should be noted that, in the following specific implementation, the WLAN IP of the second electronic device is also represented as WLAN_IP2, and the first port is also port S1. The P2P IP of the second electronic device is also represented as P2P_IP2, and the second port is also port S2.

[0014] The above method records the WLAN data path and P2P data path for transmitting the first data by setting a data path list, and selects the data path for transmitting the first data based on the existing data path in the first data path list, thereby realizing the switching between different data paths for the same service.

[0015] In one possible implementation, the P2P data path has a higher priority than the WLAN data path, and the priority is used to determine the data path for sending the first data.

[0016] The above method prioritizes the use of P2P data channels, so that after the P2P data channel is successfully established and added to the first data channel list, the first data can be automatically switched to the P2P data channel for transmission.

[0017] In one possible implementation, the method further includes: when the P2P connection fails, the first electronic device deletes the information of the P2P data path from the first data path list, sends the first data to the second electronic device via the WLAN connection, and triggers the re-establishment of the P2P connection with the second electronic device.

[0018] The above method can quickly switch the primary data to the WLAN data path when a P2P connection fails, thus avoiding data transmission lag or interruption caused by the P2P connection failure. Furthermore, by continuing to use the newly created P2P data path after reconnection, the quality of service for data transmission is guaranteed.

[0019] In one possible implementation, the first electronic device establishes a WLAN connection with the second electronic device, including:

[0020] The first electronic device establishes a WLAN control path with the second electronic device;

[0021] The first electronic device establishes a WLAN data path with the second electronic device through a WLAN control path.

[0022] In one possible implementation, before the first electronic device establishes a WLAN control path with the second electronic device, the method further includes:

[0023] The first electronic device creates a first service session, which is used to transmit first data.

[0024] The first electronic device sets the available flag of the first service session to invalid and sets the identifier of the first protocol session corresponding to the first service session to an invalid value.

[0025] The above method provides a specific implementation for establishing a WLAN connection between the first electronic device and the second electronic device.

[0026] In one possible implementation, the first electronic device establishes a WLAN data path with the second electronic device via a WLAN control path, including:

[0027] When the identifier of the first protocol session is invalid, the first electronic device creates a first protocol session and updates the identifier of the first protocol session to a valid value;

[0028] The first electronic device requests a third port on its WLAN IP.

[0029] The first electronic device sends a first message to the second electronic device. The first message carries the identifier of the first service session, the third port, and the first link type.

[0030] The first electronic device receives a first response message from the second electronic device. The first response message carries the identifier of the first service session, the identifier of the second service session, the first port, and the first link type. The second service session is a service session created by the second electronic device that corresponds to the first service session.

[0031] The above method avoids the repeated creation of the first protocol session by identifying whether the identifier of the first protocol session is valid and only creating the first protocol session when it is invalid.

[0032] In one possible implementation, after the first electronic device adds information about a WLAN data path or a P2P data path to the first data path list, the method further includes: updating the available flag to a valid value when the available flag of the first service session is set to invalid.

[0033] The above method records whether the service data (i.e., the first data) of the first service session can be transmitted by setting the available flag of the first service session, and records whether the protocol session has been created by setting the validity of the protocol session identifier. This avoids the repeated creation of the protocol session when the WLAN data path and P2P data path used to transmit the first data are created, and speeds up the data path creation process.

[0034] In one possible implementation, the first electronic device establishes a P2P connection with the second electronic device, including:

[0035] The first electronic device establishes a P2P physical connection with the second electronic device;

[0036] After the first electronic device successfully establishes a P2P physical connection, it establishes a P2P control path with the second electronic device.

[0037] The first electronic device establishes a P2P data path with the second electronic device through a P2P control path.

[0038] In one possible implementation, the first electronic device establishes a P2P data path with the second electronic device through a P2P control path. One possible implementation is as follows:

[0039] The first electronic device requests a fourth port on its P2P IP.

[0040] The first electronic device sends a third message to the second electronic device. The third message carries the identifier of the first service session, the fourth port, and the second link type.

[0041] The first electronic device receives a third response message from the second electronic device. The third response message carries the identifier of the first service session, the identifier of the second service session, the second port, and the second link type.

[0042] In one possible implementation, the method further includes: the first electronic device checking whether the identifier of the first protocol session is valid;

[0043] One way to implement the first electronic device applying for a fourth port on the P2P IP of the first electronic device is: when the identifier of the first protocol session is valid, the first electronic device applies for a fourth port on the P2P IP of the first electronic device.

[0044] The above method avoids the repeated creation of the first protocol session by identifying whether the identifier of the first protocol session is valid, thus speeding up the creation of P2P data channels.

[0045] In one possible implementation, the first electronic device includes an application, a business session management system, and a control path establishment system;

[0046] One way to implement the creation of a first service session by a first electronic device is as follows: in response to receiving a first session creation request, the service session management system creates the first service session and generates an identifier for the first service session;

[0047] One implementation of setting the available flag of the first service session to invalid and the identifier of the first protocol session corresponding to the first service session to an invalid value is as follows: The service session management system sets the available flag of the first service session to invalid and the identifier of the first protocol session corresponding to the first service session to an invalid value. The available flag of the first service session is used to indicate whether the application has been notified to transmit the first data. Before the WLAN connection is successfully established, the available flag of the first service session is invalid; setting the identifier of the first protocol session to an invalid value indicates that the first protocol session has not been established.

[0048] The above method records whether the service data (i.e., the first data) of the first service session can be transmitted by setting the available flag of the first service session, and records whether the protocol session has been created by setting the validity of the protocol session identifier. This avoids the repeated creation of the protocol session when the WLAN data path and P2P data path used to transmit the first data are created, and speeds up the data path creation process.

[0049] In one possible implementation, the first electronic device includes a service session management system and a control path establishment system, and the method further includes:

[0050] The business session management system sends a connection request to the control path establishment system. The connection request carries the WLAN IP of the first electronic device, the WLAN IP of the second electronic device, the MAC of the first electronic device, and the MAC of the second electronic device. The connection request is used to request the establishment of a WLAN connection and a P2P connection with the second electronic device.

[0051] One way to initiate the establishment of a wireless local area network (WLAN) connection with a second electronic device and to establish a point-to-point (P2P) connection with the second electronic device is as follows: In response to the connection request, the control path establishment system initiates the establishment of a WLAN control path with the second electronic device based on the WLAN IP of the first electronic device and the WLAN IP of the second electronic device, and establishes a P2P physical connection with the second electronic device based on the MAC of the first electronic device and the MAC of the second electronic device.

[0052] The above method involves the business session management system sending a connection request to the control path establishment system, simultaneously initiating the establishment of a WLAN control path with the second electronic device, and establishing a P2P physical connection with the second electronic device. The first data is transmitted using the WLAN connection first, followed by the P2P connection, thereby reducing the user's waiting time and improving the user experience.

[0053] In one possible implementation, the first electronic device includes a control path establishment system, a data path establishment system, and a protocol session management system;

[0054] Before the first electronic device creates a first protocol session and updates the identifier of the first protocol session to a valid value when the identifier of the first protocol session is invalid, the method further includes: after the control path establishment system completes the establishment of the WLAN control path, the data path establishment system sends a first data path creation request to the data path establishment system. The first data path creation request carries the WLAN IP of the first electronic device, the WLAN IP of the second electronic device and the identifier of the first service session. The first data path creation request is used to request the creation of a WLAN data path.

[0055] When the identifier of the first protocol session is invalid, the first electronic device creates a first protocol session. One implementation method is as follows: In response to the first data path creation request, when the identifier of the first protocol session is invalid, the data path establishment system sends a second session creation request to the protocol session management system. The second session creation request carries the WLAN IP of the first electronic device and is used to request the creation of the first protocol session. In response to the second session creation request, the protocol session management system creates the first protocol session and generates an identifier for the first protocol session. The first protocol session is used to encapsulate and send first data according to the requirements of the protocol.

[0056] In one possible implementation, the first electronic device further includes a service session management system. The application for a third port on the WLAN IP of the first electronic device is performed by the protocol session management system. After the first electronic device applies for a third port on the WLAN IP of the first electronic device, the method further includes: the protocol session management system sending the identifier of the first protocol session and the port number of the third port to the data path establishment system.

[0057] One implementation of the first electronic device updating the identifier of the first protocol session to a valid value is as follows: the data path establishment system sends the identifier of the first protocol session to the service session management system; in response to receiving the identifier of the first protocol session, the service session management system updates the identifier of the first protocol session to a valid value.

[0058] The above method avoids the repeated creation of the first protocol session by identifying whether the identifier of the first protocol session is valid, thus speeding up the creation of WLAN data paths.

[0059] In one possible implementation, the first electronic device includes a service session management system, a data path establishment system, and a protocol session management system; updating the available flag to a valid value can be implemented in the following way:

[0060] The protocol session management system sends the identifier of the first protocol session to the business session management system through the data path establishment system;

[0061] In response to receiving the identifier of the first service session, when the available flag of the first service session is invalid, the service session management system sends a first notification to the application. The first notification carries the identifier of the first service session and is used to indicate the transmission of the first data.

[0062] After sending the first notification, the business session management system will enable the available flag of the first business session.

[0063] The above method, after adding WLAN data path information or P2P data path information to the first data path list, updates the available flag to a valid value to record whether a data path available for the first data transmission already exists, which can avoid the service session management system repeatedly notifying the application.

[0064] In one possible implementation, the first electronic device includes a control path establishment system, a data path establishment system, and a protocol session management system;

[0065] The method further includes: after the P2P control path is established, the control path establishment system sends a second data path creation request to the data path establishment system. The second data path creation request carries the P2P IP of the first electronic device, the P2P IP of the second electronic device, and the identifier of the first service session. The second data path creation request is used to request the creation of a P2P data path.

[0066] One way for the first electronic device to check whether the identifier of the first protocol session is valid is: the data path establishment system responds to the second data path creation request and checks whether the identifier of the first protocol session corresponding to the first service session is valid.

[0067] When the identifier of the first protocol session is valid, the first electronic device requests a fourth port on the P2P IP of the first electronic device. One implementation method is as follows: when the identifier of the first protocol session is valid, the data path establishment system sends a first port request instruction to the protocol session management system. The first port request instruction carries the P2P IP of the second electronic device.

[0068] In response to the first port request instruction, the protocol session management system requests a fourth port on the P2P IP of the first electronic device.

[0069] The above method avoids the repeated creation of the first protocol session by identifying whether the identifier of the first protocol session is valid, thus speeding up the creation of P2P data channels.

[0070] In one possible implementation, the first electronic device includes a protocol session management system and a transmitting / receiving system;

[0071] Before sending the first data to the second electronic device via a WLAN connection and / or via a P2P connection, the method further includes: a protocol session management system determining the highest priority data path from a list of first data paths;

[0072] One implementation of sending first data to a second electronic device via a WLAN connection is as follows: when the protocol session management system determines that the highest priority data path is the WLAN data path, it sends a first transmission request to the transmitting and receiving system. The first transmission request carries the first data and information about the WLAN data path. In response to receiving the first transmission request, the transmitting and receiving system sends the first data to the second electronic device via the WLAN data path.

[0073] One way to send the first data to the second electronic device via a P2P connection is as follows: when the protocol session management system determines that the highest priority data path is the P2P data path, it sends a second sending request to the sending and receiving system. The second sending request carries the first data and information about the P2P data path. In response to receiving the second sending request, the sending and receiving system sends the first data to the second electronic device through the P2P data path.

[0074] In the above method, when sending the first data, the protocol session management system selects the high-priority data path based on the existing data paths in the first data path list. This enables the switching between different data paths for the same service and prioritizes the use of P2P data paths. As a result, after the P2P data path is successfully established and added to the first data path list, the first data can be automatically switched to the P2P data path for transmission.

[0075] Secondly, embodiments of this application also provide a device communication method applied to a second electronic device, the method comprising:

[0076] The second electronic device receives the first electronic device's initiative to establish a wireless local area network (WLAN) connection and a point-to-point (P2P) connection. The first electronic device and the second electronic device are respectively connected to the same wireless access point via WLAN.

[0077] After the second electronic device successfully connects to the first electronic device via WLAN, but before successfully connecting to the first electronic device via P2P, it receives the first data sent by the first electronic device via WLAN connection.

[0078] After the second electronic device successfully establishes a P2P connection with the first electronic device, it receives the first data sent by the first electronic device through the P2P connection.

[0079] In one possible implementation, the method further includes: after the second electronic device successfully establishes a WLAN connection, adding WLAN data path information to the second data path list, the WLAN data path information including the WLAN IP of the first electronic device and a third port, the first port being the port of the WLAN IP of the first electronic device; after the second electronic device successfully establishes a P2P connection, adding P2P data path information to the second data path list, the P2P data path information including the P2P IP of the first electronic device and a fourth port, the second port being the port of the P2P IP of the second electronic device.

[0080] It should be noted that, in the following specific implementation, the WLAN IP of the first electronic device is also represented as WLAN_IP1, and the third port is also port C1. The P2P IP of the first electronic device is also represented as P2P_IP1, and the fourth port is also port C2.

[0081] In one possible implementation, the P2P data path has a higher priority than the WLAN data path, and the priority is used to determine the data path for sending the second data.

[0082] In one possible implementation, the method further includes:

[0083] When the P2P connection fails, the second electronic device deletes the P2P data path information from the second data path list and receives the first data from the first electronic device via WLAN connection.

[0084] In one possible implementation, establishing a WLAN connection with the first electronic device includes:

[0085] The second electronic device establishes a WLAN control path with the first electronic device;

[0086] The second electronic device establishes a WLAN data path with the first electronic device through the WLAN control path.

[0087] In one possible implementation, the second electronic device establishes a WLAN data path with the first electronic device through a WLAN control path. One possible implementation is as follows:

[0088] The second electronic device receives a first message from the first electronic device, the first message carrying the identifier of the first service session, the third port, and the first link type;

[0089] When the second electronic device does not contain a service session corresponding to the first protocol session, it creates a second service session, sets the availability flag of the second service to invalid, and sets the identifier of the second protocol session corresponding to the second service session to invalid.

[0090] When the identifier of the protocol session corresponding to the second service session is invalid, the second electronic device creates a second protocol session and updates the identifier of the second protocol session to a valid value.

[0091] The second electronic device requests the first port on the WLAN IP of the first electronic device;

[0092] The second electronic device sends a first response message to the first electronic device. The first response message carries the identifier of the first service session, the identifier of the second service session, the first port, and the first link type.

[0093] In one possible implementation, after the second electronic device adds information about a WLAN data path to the second data path list or after the second electronic device adds information about a P2P data path to the second data path list, the method further includes: updating the available flag to a valid value when the available flag of the second service session is set to invalid.

[0094] In one possible implementation, establishing a P2P connection with a second electronic device includes:

[0095] The second electronic device establishes a P2P physical connection with the first electronic device;

[0096] After the second electronic device successfully establishes a P2P physical connection with the first electronic device, a P2P control path is established.

[0097] The second electronic device establishes a P2P data path with the first electronic device through a P2P control path.

[0098] In one possible implementation, the second electronic device establishes a P2P data path with the first electronic device through a P2P control path. One possible implementation is as follows:

[0099] The second electronic device receives a third message from the first electronic device, the third message carrying the identifier of the first service session, the fourth port, and the second link type;

[0100] The second electronic device requests a second port on the P2P IP of the second electronic device;

[0101] The second electronic device sends a third response message to the first electronic device. The third response message carries the identifier of the first service session, the identifier of the second service session, the second port, and the second link type.

[0102] In one possible implementation, the method further includes:

[0103] The second electronic device checks whether it contains a second service session corresponding to the first service session;

[0104] When the second electronic device contains a second service session, it checks whether the identifier of the second protocol session is valid.

[0105] One way to implement the second electronic device applying for a second port on the P2P IP of the second electronic device is to apply for a second port on the P2P IP of the second electronic device when the identifier of the second protocol session is valid.

[0106] In one possible implementation, the second electronic device includes a data path establishment system and a business session management system;

[0107] The method further includes: in response to the received first message, the data path establishment system sends a third session creation request to the business session management system. The third session creation request carries the identifier of the first business session and is used to request the creation of a business session corresponding to the first business session.

[0108] When a second electronic device creates a second business session without containing a business session corresponding to the first protocol session, one possible implementation is as follows: in response to a received third session creation request, the business session management system creates a second business session without containing a business session corresponding to the first business session, and sets the identifier of the second protocol session corresponding to the second business session to an invalid value.

[0109] The method further includes: the business session management system sending a second message to the data path establishment system, the second message including an identifier of the second business session, the second message being used to indicate that the second business session has been created.

[0110] In one possible implementation, the second electronic device includes a service session management system, a data path establishment system, and a protocol session management system. One way to update the available flag to a valid value is as follows: the protocol session management system sends an identifier of the second protocol session to the service session management system through the data path establishment system; upon receiving the identifier of the second service session, if the available flag of the second service session is invalid, the service session management system sends a second notification to the application program. The second notification carries the identifier of the second service session and is used to indicate that second data can be transmitted; after sending the second notification, the service session management system sets the available flag of the second service session to valid.

[0111] In one possible implementation, the second electronic device includes a data path establishment system, a protocol session management system, and a service session management system;

[0112] The method further includes: the data path establishment system sending a fifth session creation request to the business session management system, the fifth session creation request carrying the identifier of the first business session, and the fifth session creation request being used to request the creation of a second business session;

[0113] One way to check whether the second electronic device contains a second business session corresponding to the first business session is: the business session management system responds to the fifth session creation request and checks whether it contains a second business session corresponding to the first business session.

[0114] The method further includes: when the business session management system contains a second business session, sending fourth information to the data path establishment system, the fourth information including the identifier of the second business session, the fourth information being used to indicate that the second business session has been created;

[0115] When a second electronic device contains a second service session, one way to check whether the identifier of the second protocol session is valid is as follows: in response to receiving the fourth information, the data path establishment system checks whether the identifier of the second protocol session is valid.

[0116] When the identifier of the second protocol session is valid, the second electronic device requests a second port on the P2P IP of the second electronic device. One way to do this is: when the identifier of the first protocol session is valid, the data path establishment system sends a second port request instruction to the protocol session management system. The second port request instruction carries the P2P IP of the second electronic device.

[0117] In response to the second port request instruction, the protocol session management system requests a second port on the P2P IP of the second electronic device.

[0118] In one possible implementation, the second electronic device includes a transmitting / receiving system, a protocol session management system, a data path establishment system, and a service session management system. One implementation of receiving first data from the first electronic device via a WLAN connection is as follows: when the transmitting / receiving system receives the first data, it sends the port for receiving the first data to the protocol session management system, where the port for receiving the first data is designated as the first port; the protocol session management system determines the identifier of the second protocol session based on the first port and sends the first data and the identifier of the second protocol session to the data path establishment system; the data path establishment system sends the identifier of the second service session corresponding to the first data and the second protocol session to the service session management system; and the service session management system sends the first data and the identifier of the second service session to the application program.

[0119] In one possible implementation, the second electronic device includes a transmitting / receiving system, a protocol session management system, a data path establishment system, and a service session management system. One implementation of receiving first data from the first electronic device via a P2P connection is as follows: when the transmitting / receiving system receives the first data, it sends the port for receiving the first data to the protocol session management system, which is designated as a second port. The protocol session management system determines the identifier of the second protocol session based on the second port and sends the first data and the identifier of the second protocol session to the data path establishment system. The data path establishment system sends the identifier of the second service session corresponding to the first data and the second protocol session to the service session management system. The service session management system then sends the first data and the identifier of the second service session to the application program.

[0120] Thirdly, embodiments of this application also provide an electronic device, including a memory and one or more processors; the memory is coupled to the one or more processors, the memory is used to store computer program code, the computer program code including computer instructions, and the one or more processors call the computer instructions to cause the electronic device to perform the method as described in the first aspect or any possible implementation of the first aspect.

[0121] Fourthly, embodiments of this application also provide an electronic device, including a memory and one or more processors; the memory is coupled to the one or more processors, the memory is used to store computer program code, the computer program code including computer instructions, and the one or more processors call the computer instructions to cause the electronic device to perform the method as described in the second aspect or any possible implementation of the second aspect.

[0122] Fifthly, embodiments of this application also provide a computer-readable storage medium including instructions, characterized in that, when the instructions are executed on an electronic device, the electronic device causes the electronic device to perform the method as described in the first aspect or any possible implementation of the first aspect.

[0123] In a sixth aspect, embodiments of this application also provide a computer-readable storage medium including instructions, characterized in that, when the instructions are executed on an electronic device, the electronic device causes the electronic device to perform the method as described in the second aspect or any possible implementation of the second aspect.

[0124] In a seventh aspect, embodiments of this application provide a computer program product that, when run on a computer, causes the computer to perform the method as described in the first aspect or any possible implementation of the first aspect.

[0125] Eighthly, embodiments of this application provide a computer program product that, when run on a computer, causes the computer to perform the method as described in the second aspect or any possible implementation of the second aspect.

[0126] Ninthly, embodiments of this application provide a chip system including at least one processor for implementing the method as described in the first aspect or any possible implementation of the first aspect.

[0127] In a tenth aspect, embodiments of this application provide a chip system including at least one processor for implementing the method as described in the second aspect or any possible implementation of the second aspect.

[0128] It should be understood that the second to tenth aspects of this application correspond to the technical solutions of the first aspect of this application, and the beneficial effects achieved by each aspect and the corresponding possible implementations are similar, and will not be repeated here. Attached Figure Description

[0129] Figure 1 This application provides a schematic diagram of the structure of a communication system according to an embodiment of the present application.

[0130] Figures 2A to 2C The user interface provided in this application embodiment, during the screen mirroring process from a first device to a second device, is shown in the schematic diagram.

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

[0132] Figure 4 A schematic diagram of the hardware and software structure of an electronic device provided in an embodiment of this application;

[0133] Figures 5A to 5E This application provides a schematic flowchart of a device communication method.

[0134] Figures 6A to 6B The user interface involved in another screen mirroring process from a first device to a second device, provided in an embodiment of this application, is shown in the diagram.

[0135] Figure 7 A flowchart illustrating a device communication method in the event of a P2P link failure, provided as an embodiment of this application;

[0136] Figure 8 A flowchart illustrating another device communication method provided in an embodiment of this application;

[0137] Figure 9A A flowchart illustrating a method for a first device and a second device to negotiate and establish a WLAN data path, provided as an embodiment of this application;

[0138] Figure 9B A flowchart illustrating a method for a first device and a second device to negotiate and establish a P2P data path, provided in an embodiment of this application;

[0139] Figure 10 This is a flowchart illustrating another device communication method for P2P link abnormalities provided in an embodiment of this application. Detailed Implementation

[0140] The technical solutions in the embodiments of this application will be clearly and thoroughly described below with reference to the accompanying drawings. In the description of the embodiments of this application, unless otherwise stated, " / " means "or," for example, A / B can mean A or B; the word "and / or" in the text is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Furthermore, in the description of the embodiments of this application, "multiple" refers to two or more than two.

[0141] Hereinafter, the terms "first" and "second" are used for descriptive purposes only and should not be construed as implying or suggesting relative importance or implicitly indicating the number of indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature, and in the description of the embodiments of this application, unless otherwise stated, "multiple" means two or more.

[0142] The device communication method provided in this application can be applied to scenarios that are sensitive to latency or have high requirements, such as call sharing, notification sharing, keyboard and mouse sharing, multi-screen collaboration, screen mirroring / extension, video on demand / live streaming, etc., among multiple devices in a wireless local area network.

[0143] Figure 1 The diagram shown is a structural schematic of a communication system provided in an embodiment of this application. The communication system may include a wireless access point (AP) 10, such as a router, and multiple devices connected to the AP 10, such as a first device 20 and a second device 30. The first device 20 may initiate data transmission services to the second device 30, such as multi-screen collaboration, screen mirroring, call sharing, keyboard and mouse sharing, and other latency-sensitive or high-requirement services.

[0144] To overcome the problem of long P2P connection times and long user waiting times when the first device 20 initiates a P2P connection to the second device 30, this embodiment of the application proposes that when the first device 20 initiates a first service session to the second device 30, the first device 20 and the second device 30 can simultaneously trigger the establishment of a WLAN connection and a P2P connection. Since the first device and the second device have already completed a physical WLAN connection, the WLAN connection between the first device and the second device needs to establish a WLAN control channel and a WLAN data channel. However, the P2P connection between the first device and the second device requires first establishing a physical P2P connection, and then establishing the P2P control channel and the P2P data channel. Therefore, the WLAN connection will be completed faster. The first device 20 can send the service data of the first service session to the second device via the WLAN connection after the WLAN connection is successful but before the P2P connection is successful. After the P2P connection is successful, it sends the service data of the first service session to the second device via the P2P connection, thereby reducing user waiting time and prioritizing the use of P2P to transmit service data, thus improving the service quality.

[0145] In this embodiment of the application, the first device 20 or the second device 30 may not be limited to... Figure 1 The mobile phones and laptops shown can also be desktop computers, laptops, handheld computers, tablets, ultra-mobile personal computers (UMPCs), netbooks, cellular phones, personal digital assistants (PDAs), augmented reality (AR) devices, virtual reality (VR) devices, artificial intelligence (AI) devices, wearable devices, in-vehicle devices, smart home devices, and / or smart city devices. The embodiments of this application do not impose any special restrictions on the specific type of terminal.

[0146] The following example illustrates the device communication process using a scenario where a first device (such as a mobile phone) initiates screen mirroring to a second device (such as a laptop).

[0147] Figures 2A to 2C The example illustrates the user interface during the screen mirroring process from a first device to a second electronic device. In this scenario, the device communication process includes the following steps:

[0148] like Figure 2AAs shown, the mobile phone can display user interface 201, and the personal computer can display user interface 202. The user interface 201 may include a "connect" control and a "cancel" control. The user can click the "connect" control, and the mobile phone, in response to the click operation on the "connect" control, can simultaneously initiate the establishment of a WLAN connection and a P2P connection.

[0149] WLAN connections are established much faster than P2P connections.

[0150] like Figure 2B As shown, when the WLAN connection is successful, the P2P connection has not yet been established. The mobile phone can use the WLAN connection to transmit screen projection data. At this time, the user interface 204 displayed on the personal computer can include the user interface 203 of the mobile phone.

[0151] like Figure 2C As shown, once the P2P connection is successful, the mobile phone switches the screen projection data from the WLAN connection to the P2P connection, and then uses the P2P connection to transmit the screen projection data. At this time, the user interface 206 displayed on the personal computer can include the user interface 205 of the mobile phone.

[0152] In another implementation, once the P2P connection is successful, the mobile phone can transmit screen projection data using the P2P connection, or it can transmit screen projection data using the WLAN connection simultaneously, or it can transmit screen projection data without using the WLAN connection.

[0153] The apparatus involved in the embodiments of this application is described below.

[0154] like Figure 3 As shown, this is an electronic device 100 provided in an embodiment of this application. The electronic device 100 can be the one described above. Figure 1 , Figures 2A-2C The first or second device in the electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, a headphone jack 170D, a sensor module 180, a camera 191, a display screen 192, and a subscriber identification module (SIM) card interface 193, etc. The sensor module 180 may include one or more of the following: a pressure sensor, a gyroscope sensor, a barometric pressure sensor, a magnetic sensor, an accelerometer, a distance sensor, a proximity sensor, a fingerprint sensor, a temperature sensor, a touch sensor, an ambient light sensor, a bone conduction sensor, etc.

[0155] It is understood that the structures illustrated in the embodiments of the present invention do not constitute a specific limitation on the electronic device 100. In other embodiments of this application, the electronic device 100 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.

[0156] Processor 110 may include one or more processing units, such as application processors (APs), modem processors, graphics processing units (GPUs), image signal processors (ISPs), controllers, video codecs, digital signal processors (DSPs), baseband processors, and / or neural network processing units (NPUs). These different processing units may be independent devices or integrated into one or more processors. The processor is used to implement the logic for multi-device collaborative management, such as service connection establishment logic, service disconnection logic, and service mode switching logic.

[0157] The processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory.

[0158] In some embodiments, the processor 110 may include one or more interfaces. It is understood that the interface connection relationships between the modules illustrated in the embodiments of the present invention are merely illustrative and do not constitute a structural limitation on the electronic device 100.

[0159] The wireless communication function of electronic device 100 can be realized through antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, modem processor and baseband processor, etc.

[0160] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 100 can be used to cover one or more communication frequency bands. Different antennas can also be multiplexed to improve antenna utilization. For example, antenna 1 can be multiplexed as a diversity antenna for a wireless local area network. In some other embodiments, the antennas can be used in conjunction with tuning switches.

[0161] The mobile communication module 150 can provide solutions for wireless communication, including 2G / 3G / 4G / 5G, applied to the electronic device 100. The mobile communication module 150 may include at least one filter, switch, power amplifier, low noise amplifier (LNA), etc. The mobile communication module 150 can receive electromagnetic waves via antenna 1, and perform filtering, amplification, and other processing on the received electromagnetic waves before transmitting them to a modem processor for demodulation. The mobile communication module 150 can also amplify the signal modulated by the modem processor and convert it into electromagnetic waves for radiation via antenna 1. In some embodiments, at least some functional modules of the mobile communication module 150 may be housed in the processor 110. In some embodiments, at least some functional modules of the mobile communication module 150 and at least some modules of the processor 110 may be housed in the same device.

[0162] A modem processor may include a modulator and a demodulator. The modulator modulates the low-frequency baseband signal to be transmitted into a mid-to-high frequency signal. The demodulator demodulates the received electromagnetic wave signal into a low-frequency baseband signal.

[0163] The wireless communication module 160 can provide solutions for wireless communication applications on the electronic device 100, including wireless local area networks (WLANs) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), and infrared (IR) technologies. The wireless communication module 160 can be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via antenna 2, performs frequency modulation and filtering of the electromagnetic wave signals, and sends the processed signal to processor 110. The wireless communication module 160 can also receive signals to be transmitted from processor 110, perform frequency modulation and amplification, and convert them into electromagnetic waves for radiation via antenna 2.

[0164] In some embodiments, antenna 1 of electronic device 100 is coupled to mobile communication module 150, and antenna 2 is coupled to wireless communication module 160, enabling electronic device 100 to communicate with networks and other devices via wireless communication technology. The wireless communication technology may include Global System for Mobile Communications (GSM), General Packet Radio Service (GPRS), Code Division Multiple Access (CDMA), Wideband Code Division Multiple Access (WCDMA), Time Division Code Division Multiple Access (TD-SCDMA), Long Term Evolution (LTE), BT, GNSS, WLAN, NFC, FM, and / or IR technologies, etc. The GNSS may include the Global Positioning System (GPS), the Global Navigation Satellite System (GLONASS), the BeiDou Navigation Satellite System (BDS), the Quasi-Zenith Satellite System (QZSS), and / or satellite-based augmentation systems (SBAS).

[0165] Electronic device 100 implements display functions through a GPU, display screen 192, and application processor. Display screen 192 is used to display images, videos, etc.

[0166] Electronic device 100 can perform shooting functions through an image signal processor (ISP), camera 191, video codec, GPU, display screen 192, and application processor. Camera 191 is used to capture still images or videos.

[0167] Internal memory 121 can be used to store computer executable program code, which includes instructions. Processor 110 performs various functional applications and data processing of electronic device 100 by executing instructions stored in internal memory 121 and / or instructions stored in memory disposed in the processor.

[0168] Electronic device 100 can implement audio functions, such as music playback and recording, through audio module 170, speaker 170A, receiver 170B, microphone 170C, headphone jack 170D, and application processor.

[0169] The SIM card interface 193 is used to connect a SIM card. The SIM card can be inserted into or removed from the SIM card interface 193 to make contact with or separate from the electronic device 100.

[0170] Figure 4 This is a schematic diagram of the hardware and software structure of an electronic device provided in an embodiment of this application.

[0171] like Figure 4 As shown, the hardware and software architecture of electronic devices can adopt a layered architecture. A layered architecture divides the system into several layers, each with a clear role and division of labor. Layers communicate with each other through software interfaces.

[0172] like Figure 4 As shown, the hardware and software architecture framework of the electronic device involved in this application may include an application layer, an application framework layer (FWK), system libraries and Android runtime, a hardware abstraction layer (HAL) (not shown), a kernel layer, and a hardware layer.

[0173] The application layer can include a series of applications. For example, the application package can include WLAN applications, Bluetooth applications, application connection, call sharing, notification sharing, keyboard and mouse sharing, file sharing, screen casting, video and gallery applications, as well as other applications not shown, such as music, camera, browser and other applications.

[0174] Among them, the WLAN application is mainly used to enable, connect to, and set up WLAN, while the Bluetooth application is used to enable, connect to, and set up Bluetooth. The application continuation application enables the electronic device to continue the application content and usage status with nearby devices. The call sharing application enables nearby devices to answer and continue calls from this electronic device; for example, a smart screen can answer calls from this electronic device, while tablets and computers also support making calls. The notification sharing application enables nearby devices to receive notifications from this electronic device and supports processing on these devices. The keyboard and mouse sharing application enables this electronic device to share input devices with nearby computers, or allows a computer or tablet's mouse, keyboard, and touchpad to be shared with this electronic device. It also enables cross-device file transfer and cross-device window display and use. The file sharing application enables wireless file sharing with other electronic devices on the same network, enabling rapid file sharing or printing. The screen mirroring application enables the local device to link with a large-screen device to display videos and other content displayed on this electronic device, or to link the local device with a small-screen device to display videos and other content displayed on the small-screen device on the large screen of this electronic device. Here, "large screen" and "small screen" refer to the relative size of the display screen of electronic devices.

[0175] The application framework layer provides an Application Programming Interface (API) and programming framework for applications in the application layer. The application framework layer includes some predefined functions. It may include a window manager, content provider, view system, and resource manager, etc. (not shown in the diagram).

[0176] The application framework layer also includes a service session management system, a control path establishment system, a data path establishment system, a protocol session management system, and a send / receive system. The specific functional implementations of the service session management system, control path establishment system, data path establishment system, protocol session management system, and send system can be found below. Figures 5A-5E and Figure 7 The method shown will not be elaborated here.

[0177] The runtime is responsible for system scheduling and management. The runtime includes the core libraries and the virtual machine. The core libraries consist of two parts: one part contains the functionalities that the programming language (e.g., Java) needs to call, and the other part contains the system's core libraries.

[0178] The application layer and application framework layer run in a virtual machine. The virtual machine executes the programming files (e.g., Java files) of the application layer and application framework layer as binary files. The virtual machine is used to perform functions such as object lifecycle management, stack management, thread management, security and exception management, and garbage collection.

[0179] System libraries can include multiple functional modules. For example: Surface Manager, Media Libraries, 3D image processing libraries (e.g., OpenGL ES), 2D graphics engines (e.g., SGL), etc.

[0180] The Surface Manager is used to manage the display subsystem and provides the fusion of two-dimensional (2D) and three-dimensional (3D) layers for multiple applications.

[0181] The media library supports playback and recording of various common audio and video formats, as well as still image files. It supports multiple audio and video encoding formats, such as MPEG4, H.264, MP3, AAC, AMR, JPG, and PNG.

[0182] The 3D image processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.

[0183] A 2D graphics engine is a graphics engine for 2D drawing.

[0184] The Hardware Abstraction Layer (HAL) is an interface layer located between the operating system kernel and upper-level software, its purpose being to abstract hardware. The HAL is an abstract interface for device kernel drivers, providing application programming interfaces (APIs) for accessing the underlying devices to higher-level Java API frameworks. The HAL contains multiple library modules, each implementing an interface for a specific type of hardware component.

[0185] The kernel layer is the foundation of the Android operating system; all of Android's final functions are implemented through the kernel layer. The kernel layer can contain drivers such as WiFi, Bluetooth, display, camera, and audio. The Bluetooth driver drives the Bluetooth module. The WiFi driver drives the WiFi module.

[0186] The hardware layer can include WiFi modules, Bluetooth modules, and may also include displays, microphones, cameras, memory, audio encoders, and video encoders, etc.

[0187] It should be noted that the application provides Figure 4 The illustrated software architecture diagram of the electronic device is for illustrative purposes only.

[0188] This application does not limit the specific module divisions within different layers of the Android operating system; for details, please refer to the general technical descriptions of the Android operating system software architecture. Furthermore, the device communication method provided in this application can also be implemented based on other operating systems, which will not be listed here.

[0189] The following describes a device communication method provided in an embodiment of this application. This method can be applied to the above-mentioned... Figure 1 The communication system shown, Figures 2A-2C The scene and interface shown, the first device and the second device in this method can be as described above. Figure 3 The electronic device shown can be adopted Figure 4 The software and hardware architecture of the electronic device shown.

[0190] Example 1

[0191] Example 1 combined Figures 5A-5E A flowchart of a device communication method is provided, wherein, Figures 5A-5B The process of initiating a data transmission service, simultaneously creating a WLAN control path and a P2P control path, creating and initializing the resources used by the service session, and creating a WLAN data path are illustrated. Figure 5C This illustrates the process of sending screen projection data after the WLAN data path is successfully established but before the P2P data path is successfully established. Figure 5D The process of successfully establishing a P2P control path and creating a P2P data path is illustrated. Figure 5E This illustrates the process of sending projection data after the P2P data path is successfully established.

[0192] The communication method of this device may include, but is not limited to, some or all of the following steps:

[0193] S01, the screen mirroring application of the first device receives the screen mirroring operation, which is used to instruct the screen to be mirrored to the second device.

[0194] Specifically, after receiving a user's screen mirroring operation, the screen mirroring application of the first device can determine the currently available devices. One implementation of the first device determining the currently available devices could be: as follows... Figure 6AAs shown, the first device can display the interface of the screen mirroring application. When the wireless screen mirroring function is turned on, the screen mirroring application can send a request to the networking module to request the list of device identifiers under the current network. In response to the request, the networking module will send the list of device identifiers under the current network to the screen mirroring application. The first device displays the list of device identifiers on the screen mirroring application interface. The list of device identifiers includes the identifiers of available devices under the same WiFi network. The first device displays the list of device identifiers. Furthermore, the user can click on the identifier of the second device in the list of device identifiers. At this time, the screen mirroring application of the first device receives the user's operation to mirror the screen to the second device.

[0195] For example, such as Figure 2A As shown, the first device (mobile phone) can display a user interface for connecting with the second device (laptop). Furthermore, in response to a user operation input to the "connect" control on the user interface, such as a click operation, the first device receives a screen mirroring operation to the second device.

[0196] The aforementioned screen mirroring operation is also known as a user operation used to instruct the sending of first data to a second device; the screen mirroring data is also known as the first data.

[0197] It should be understood that before the first device initiates a data transmission service, such as screen mirroring, the first device and the second device are already connected to the same AP via WLAN and are on the same wireless local area network.

[0198] S02, the screen mirroring application of the first device responds to the user operation by sending a first session creation request to the business session management system. The first session creation request carries the identifier of the second device and is used to request the creation of a screen mirroring business session.

[0199] S03, the service session management system of the first device obtains the address information of the second device based on the identifier of the second device.

[0200] Specifically, the service session management system can send a request to the networking module, carrying the identifier of the second device, to request the WLAN IP address (also referred to as WLAN_IP2 in this application) and the MAC address (also referred to as MAC2 in this application) of the second device. In response to this request, the networking module sends the IP address of the second device to the service session management system.

[0201] The first device can also obtain its local WLAN IP address (represented as WLAN_IP1) and local MAC address (represented as MAC1).

[0202] Among them, WLAN_IP1 and WLAN_IP2 are used to establish WLAN control paths, and MAC1 and MAC2 are used to establish P2P physical connections between the first device and the second device.

[0203] S04, the service session management system of the first device responds to the first session creation request, creates the first service session, generates the identity document (ID) of the first service session, sets the available flag of the first service session to invalid, and initializes the identifier of the protocol session corresponding to the first service session to an invalid value (False).

[0204] The first service session is used for data interaction between the first device and the application, sending and receiving data for the application. The attributes of the first service session may include a flag bit (also known as the availability flag bit) indicating whether the first service session is available. When the first service session is created, the availability flag bit of the first service session is set to invalid (false).

[0205] The available flag of the first service session indicates whether the screen-casting application has been notified that it can transmit the service data of the first service session, i.e., the screen-casting data. Before the data path (such as a WLAN data path) used to transmit the service data of the first service session is successfully established, the available flag of the first service session is invalid. After the data path (such as a WLAN data path) used to transmit the service data of the first service session is successfully established, the service session management system will send a first notification to the screen-casting application to inform it that the service data of the first service session can be transmitted. After the first notification is sent, the service session management system will modify the available flag of the first service session to be valid to record that the screen-casting application has been notified that the service data of the first service session can be transmitted.

[0206] It should be understood that at this point, the protocol session corresponding to the first business session (i.e., the first protocol session) has not yet been created. When the business session management system creates the first business session, it initializes the ID of the first protocol session to an invalid value. The business session management system of the first device can determine whether the protocol session has been created based on whether the ID of the first protocol session is valid. After the first protocol session is created, the business session management system will update the ID of the first protocol session to a valid value.

[0207] S05, the service session management system of the first device sends a connection request to the control path establishment system. This connection request is used to request the establishment of a WLAN connection and a P2P connection with the second device. The connection request carries the WLAN IP of the first device (i.e., WLAN_IP1), the WLAN IP of the second device (i.e., WLAN_IP2), the MAC of the first device (i.e., MAC1), the MAC of the second device (i.e., MAC2), and the ID of the first service session (represented as A1_ID).

[0208] WLAN_IP1 and WLAN_IP2 are used to establish a WLAN control path between the first and second devices. MAC1 and MAC2 are used to establish a P2P physical connection between the first and second devices.

[0209] In response to the creation request, the first device can simultaneously establish a WLAN connection and a P2P connection, meaning it can simultaneously begin executing S06 and S07. Since both the first and second devices are already connected to the AP (and have completed the WLAN physical connection), the process of establishing a WLAN connection between the first and second devices is a socket establishment process, including establishing a WLAN control path between the first and second devices, and further, establishing a WLAN data path between the first and second devices through this WLAN control path.

[0210] During the P2P connection establishment process between the first and second devices, a physical P2P connection must first be established between them. Then, a socket establishment occurs, meaning the first and second devices establish a P2P control path. Further, a P2P data path is established between them through this control path. Therefore, a successful WLAN connection usually precedes a successful P2P connection.

[0211] Optionally, the control path establishment system of the first device records a table showing the relationship between the ID of the first service session and the establishment action.

[0212] The following steps describe the process: S06 describes the establishment of the WLAN control path, and S08-S33 describe the creation of the WLAN data path. S34-S47 describe the process after the first and second devices successfully establish the WLAN data path, recording the WLAN path in their respective data path lists and notifying the screen projection application that service data can be transmitted. S48-S59 describe the process after the WLAN data path is successfully established but before the P2P data path is successfully established, whereby the first device sends screen projection data through the WLAN data path. The following steps describe the process of the first and second devices establishing a P2P physical connection: S07 describes the process of the first and second devices forming a P2P physical connection; S60-S61 describe the establishment of the P2P control path; S62-S78 describe the establishment of the P2P data path; S79-S88 describe the process after the first and second devices successfully establish the P2P data path, recording the P2P path in their respective data path lists; and S89-S100 describe the process before the P2P data path is successfully established, whereby the first device sends screen projection data through the WLAN data path.

[0213] S06, the control path establishment system of the first device and the control path establishment system of the second device perform a three-way handshake on the TCP protocol through WLAN to establish a WLAN control path.

[0214] Since both the first and second devices are already connected to the wireless LAN, the WLAN connection between them is established through a socket process. Specifically, a three-way handshake using the TCP protocol is performed on the WLAN link to establish the WLAN control path. This handshake requires knowledge of the WLAN IPs (i.e., WLAN_IP1 and WLAN_IP2) of both the local (first device) and the peer (second device). If the handshake is successful, the first device confirms that the WLAN control path has been successfully established.

[0215] S07, the control path establishment system of the first device and the control path establishment system of the second device establish a P2P physical connection.

[0216] In response to the above connection request, the first device and the second device establish a P2P physical connection. After the P2P physical connection is successful, the socket is established, that is, S60-S78 is executed.

[0217] The P2P physical connection between the first device and the second device requires the use of the MAC addresses of the local end and the peer end (i.e., MAC1 and MAC2).

[0218] S08, after the WLAN control path is successfully established (i.e., the three-way handshake is successful), the control path establishment system of the first device sends a first data path creation request to the data path establishment system. The first data path creation request carries the WLAN IP of the first device (i.e., WLAN_IP1), the WLAN IP of the second device (i.e., WLAN_IP2), and the ID of the first service session (i.e., A1_ID) to request the establishment of a WLAN data path.

[0219] S09, the data path establishment system of the first device responds to the first data path creation request by checking whether the ID of the first protocol session corresponding to the ID of the first service session is valid.

[0220] At this point, the first protocol session has not yet been created, and the ID of the first protocol session is invalid. S10 can be executed. Conversely, if it is valid, it means that the first protocol session has been created. At this point, a request to apply for a port can be sent to the protocol session management system of the first device. Further, S12 can be executed.

[0221] S10, when the ID of the first protocol session is invalid, the data path establishment system of the first device sends a second session creation request to the protocol session management system. The second session creation request carries the WLAN IP of the first device (i.e., WLAN_IP1) and is used to request the creation of the protocol session corresponding to the first service session (i.e., the first protocol session).

[0222] S11, the protocol session management system of the first device responds to the second session creation request and creates the protocol session corresponding to the first service session, i.e., the first protocol session, to generate the ID (i.e., B1_ID) of the identifier of the first protocol session.

[0223] S12, the protocol session management system of the first device requests a User Datagram Protocol (UDP) port on the local WLAN IP (i.e., WLAN_IP1), which is exemplarily represented as port C1.

[0224] Specifically, the protocol session management system performs port binding on WLAN_IP1 and randomly obtains a UDP protocol port, such as port C1.

[0225] S13, the protocol session management system of the first device sends the ID (i.e., B1_ID) and port C1 of the first protocol session to the data path establishment system. The first protocol session is used by the first device to encapsulate and send service data from the first service session according to the protocol requirements.

[0226] S14, the data path establishment system of the first device sends the ID of the first protocol session (i.e., B1_ID) to the service session management system.

[0227] S15, the service session management system of the first device refreshes the ID of the first protocol session corresponding to the first service session.

[0228] At this point, the ID of the first protocol session changes from an invalid value to a valid value, namely B1_ID.

[0229] S16, the service session management system of the first device sends first information to the data path establishment system. The first information may carry the ID of the first service session (i.e., A1_ID) to indicate that the ID of the first protocol session has been refreshed.

[0230] S17, after receiving the first information, the data path establishment system of the first device can send a first message to the data path establishment system of the second device through the WLAN control path. The first message carries the port C1 of the first device, the ID of the first service session (i.e., A1_ID) and the link type WLAN, and is used to negotiate the establishment of a WLAN data path.

[0231] S18, after receiving the first message, the data path establishment system of the second device parses the first message to obtain the UDP port C1, A1_ID, link type WLAN, and the WLAN IPs of both ends (i.e. WLAN_IP1 and WLAN_IP2) of the first device.

[0232] Specifically, the data path establishment system of the second device can parse the first message to obtain the port C1 of the first device, the ID of the first service session (i.e., A1_ID) and the link type WLAN carried in the first message.

[0233] The data path establishment system of the second device can also obtain the source address (i.e., WLAN_IP1) and the destination address (i.e., WLAN_IP2) of the first packet when the link type is WLAN.

[0234] S19, the data path establishment system of the second device sends a third session creation request to the service session management system. The third session creation request carries the ID of the first service session (i.e., A1_ID).

[0235] S20, the service session management system of the second device responds to the third session creation request by checking whether the local end contains the service session corresponding to the ID of the first service session.

[0236] Since the service session management system of the second device has not yet created the service session corresponding to the second service session, it does not include the service session corresponding to the first service session. At this time, S21 can be executed. Otherwise, when the service session corresponding to the service session system has been established, the service session management system of the second device sends information carrying the ID of the service session (i.e., the second service session) corresponding to the ID of the first service session to the data path establishment system to indicate that the second service session has been created.

[0237] S21, when the service session management system of the second device does not have a service session corresponding to the ID of the first service session on the local end, it creates a second service session to generate the second service session ID (i.e., A2_ID), sets the available flag of the second service session to invalid, and initializes the ID of the protocol session (i.e., the second protocol session) corresponding to the second service session to an invalid value (False).

[0238] The second service session is used for data interaction with applications (such as screen mirroring applications) on the second device, sending and receiving data for the application.

[0239] It should be understood that at this point, the protocol session corresponding to the second business session (the second protocol session) has not yet been created. When the business session management system creates the second business session, it initializes the ID of the corresponding second protocol session to an invalid value. The business session management system of the first device can determine whether the second protocol session has been created based on whether the ID of the second protocol session is valid. After the second protocol session is created, the business session management system will update the ID of the second protocol session to a valid value.

[0240] Similar to the first service session mentioned above, the second service session may also include a flag (also known as an availability flag) to indicate whether the second service session is available. When creating the second service session, the availability flag is set to invalid (false).

[0241] S22, the service session management system of the second device sends second information to the data path establishment system. The second information may carry the identifier of the second service session (i.e., A2_ID) to indicate that the second service session has been created.

[0242] S23, after receiving the second information, the data path establishment system of the second device can check whether the ID of the second protocol session corresponding to the second service session is valid.

[0243] At this point, the second protocol session has not yet been created, and the ID of the second protocol session is an invalid value.

[0244] If the ID of the second protocol session is valid, it means that the second protocol session has been created. At this time, a request to apply for a port can be sent to the protocol session management system of the second device. Further, S26 is executed.

[0245] S24, when the ID of the second protocol session is invalid, the data path establishment system of the second device sends a fourth session creation request to the protocol session management system. The fourth session creation request carries WLAN_IP2 and is used to request the creation of the protocol session corresponding to the second service session.

[0246] S25, the protocol session management system of the second device responds to the fourth session creation request and creates the protocol session corresponding to the second service session, namely the second protocol session, to generate the ID of the second protocol session (i.e., B2_ID).

[0247] The second protocol session is used by the second device to receive and parse the received data according to the requirements of the protocol in order to obtain the service data of the first service session.

[0248] S26, the protocol session management system of the second device requests a UDP port on the local WLAN IP (WLAN_IP2), which is exemplarily represented as port S1.

[0249] S27, the protocol session management system of the second device sends the ID (i.e., B2_ID) and port S1 of the second protocol session to the data path establishment system.

[0250] S28, the data path establishment system of the second device sends the ID of the second protocol session (i.e., B2_ID) to the service session management system.

[0251] S29, the service session management system of the second device refreshes the ID of the second protocol session.

[0252] At this point, the ID of the second protocol session changes from an invalid value to a valid value, namely B2_ID.

[0253] S30, the service session management system of the second device sends third information to the data path establishment system. This third information may carry the ID of the second service session (i.e., A2_ID) to indicate that the ID of the second protocol session has been updated.

[0254] S31, the data path establishment system of the second device sends a first response message to the data path establishment system of the first device through the WLAN control path. The first response message is a response message to the first message, carrying the ID of the first service session (i.e., A1_ID), the ID of the second service session (i.e., A2_ID), the link type WLAN, and the port S1.

[0255] S32, after receiving the first response message, the data path establishment system of the first device sends a first protocol connection instruction to the protocol session management system. The first protocol connection instruction carries the WLAN IP (i.e., WLAN_IP2), port S1, and ID (i.e., B1_ID) of the peer (i.e., the second device).

[0256] It should be understood that after receiving the first response message, the data path establishment system of the first device can determine the ID of the first protocol session (i.e., B1_ID) corresponding to the ID of the first service session.

[0257] S33, the protocol session management system of the first device responds to the first protocol connection command and performs a protocol handshake with the protocol session management system of the second device to exchange their respective protocol session IDs.

[0258] Specifically, the protocol session management system of the first device sends a second message to the protocol session management system of the second device, which carries the ID of the first protocol session (i.e., B1_ID). After receiving the second message, the protocol session management system of the second device sends a second response message to the protocol session management system of the second device, which carries the ID of the second protocol session (i.e., B2_ID). At this point, both the protocol session management systems of the first and second devices confirm that the handshake has been completed.

[0259] S34, after completing the protocol handshake, the protocol session management system of the first device adds the WLAN data path to the first data path list.

[0260] Specifically, in the protocol session management system, each protocol session can correspond to a data path list. The data path list corresponding to the ID of the first protocol session is also known as the first data path list. The protocol session management system can also set priorities for the data paths in this data path list; for example, the priority of P2P data paths is higher than that of WLAN data paths. When multiple available data paths exist for a session, the protocol session management system will prioritize the data path with the higher priority for sending service data.

[0261] Specifically, the protocol session management system of the first device maintains a list of first data paths corresponding to the ID (B1_ID) of the first protocol session. The list of first data paths may include information on one or more data paths. The recorded information on the WLAN data path includes the WLAN IP and port of the peer, such as WLAN_IP2 and port S1.

[0262] S35, the protocol session management system of the first device sends the ID (i.e., B1_ID) of the first protocol session and the link type WLAN to the data path establishment system.

[0263] S36, the data path establishment system of the first device sends the ID (i.e., A1_ID) and link type WLAN of the first service session to the service session management system.

[0264] S37, the service session management system of the first device adds a WLAN data path to the list of third data paths corresponding to the ID of the first service session.

[0265] Specifically, the service session management system of the first device maintains a list of data paths (i.e., the third data path list) corresponding to the ID (A1_ID) of the first service session. The information of the WLAN data paths included in the third data path list may include the link type WLAN, so that the service session management system of the first device knows the number of data paths currently available for the first service session and the link type to which they belong.

[0266] S38, the service session management system of the first device checks whether the available flag of the first service session is valid.

[0267] The available flag indicates whether a service session can transmit service data or whether a notification indicating that data transmission is possible should be sent. When the available flag for the first service session is invalid, the service session management system does not send a notification to the projection application indicating that the first service session has been successfully opened or that service data can be transmitted, and the projection application will not distribute the service data for the first service session. Conversely, when the available flag for the first service session is valid, the service session management system has sent a notification to the projection application indicating that the first service session has been successfully opened or that service data can be transmitted, and the projection application has distributed the service data for the first service session.

[0268] At this time, the available flag for the first service session is invalid (false).

[0269] S39, when the service session management system of the first device is invalid, it sends a first notification to the screen projection application. The first notification may carry the ID of the first service session (i.e., A1_ID) to indicate that the first service session has been successfully opened or that the service data of the first service session can be transmitted. At this time, the service data (i.e., screen projection data) can be transmitted.

[0270] In step S40, the service session management system of the first device sets the available flag of the first service session to true after step S39. At this time, the screen mirroring application has been notified that it can send service data.

[0271] Accordingly, after S33, the second device can also perform the same operations as S34-S40 described above, as detailed in steps S41-S47 below.

[0272] S41, after completing the protocol handshake, the protocol session management system of the second device adds the WLAN data path to the second data path list.

[0273] Specifically, the protocol session management system of the second device maintains a list of data paths corresponding to the ID of the second protocol session, i.e., the second data path list. This second data path list may include information on one or more data paths. The recorded WLAN data path information includes the WLAN IP and port of the peer, i.e., WLAN_IP1 and port C1. S42, the protocol session management system of the second device sends the ID (i.e., B2_ID) of the second protocol session and the link type WLAN to the data path establishment system.

[0274] S43, the data path establishment system of the second device sends the ID (i.e., A2_ID) of the second service session and the link type WLAN to the service session management system.

[0275] S44, the service session management system of the second device adds a WLAN data path to the fourth data path list.

[0276] Specifically, the service session management system of the second device maintains a list of data paths corresponding to the ID of the second service session (i.e., the fourth data path list). The information of the WLAN data paths included in the fourth data path list may include the link type WLAN, so that the service session management system of the second device knows the number of data paths currently available for the second service session and the link type to which they belong.

[0277] S45, the service session management system of the second device checks whether the available flag of the second service session is valid.

[0278] When the availability flag of the second service session is invalid, the service session management system does not send a notification to the screen projection application indicating that the second service session has been successfully opened or that the service data of the second service session can be transmitted. Therefore, the screen projection application will not send the service data for the second service session. Conversely, when the availability flag of the second service session is valid, the service session management system has sent a notification to the screen projection application indicating that the second service session has been successfully opened or that the service data of the second service session can be transmitted. Therefore, the screen projection application has already sent the service data for the second service session.

[0279] At this time, the available flag for the second service session is invalid (false).

[0280] S46, when the service session management system of the second device is invalid for the available flag of the second service session, it sends a second notification to the screen projection application. The second notification may carry the ID of the second service session (i.e., A2_ID) to indicate that the second service session has been successfully opened or that the service data of the second service session can be transmitted. At this time, the service data can be transmitted.

[0281] The available flag is used to indicate whether a service session can transmit service data. When the available flag of a service session is invalid, the screen projection application does not receive a notification indicating that the second service session has been successfully opened, and therefore will not send the service data of the second service session, such as the data used to control screen projection on the second device side.

[0282] In step S47, the service session management system of the second device sets the available flag of the second service session to true after step S46. At this point, the screen mirroring application has been notified that it can send service data.

[0283] It should be understood that steps S37 and S44 above are not mandatory. In some embodiments, the device's service session management system may not include a list of data paths corresponding to the service session.

[0284] It should be understood that after S39, the screen mirroring application on the first device can send service data of the first service session to the screen mirroring application on the second device. Specifically, such as... Figure 5C The flowchart shown may illustrate that the process of sending business data may include, but is not limited to, some or all of the following steps S48-S59:

[0285] S48, after receiving the first notification, the screen mirroring application of the first device can send the business data (i.e., screen mirroring data) of the first business session and the ID (i.e., A1_ID) of the first business session to the business session management system.

[0286] S49, after receiving the projection data and the ID of the first service session, the service session management system of the first device sends the projection data and the ID of the first service session (i.e., A1_ID) to the data path establishment system.

[0287] S50, the data path establishment system of the first device sends the screen projection data and the ID of the first protocol session (i.e., B1_ID) to the protocol session management system.

[0288] The data path establishment system of the first device stores the correspondence between the ID of the first service session (i.e., A1_ID) and the ID of the first protocol session (i.e., B1_ID). Therefore, after the data path establishment system receives the projection data and A1_ID, it can determine the B1_ID corresponding to A1_ID, and then send the projection data and B1_ID to the protocol session management system.

[0289] S51, after receiving the screen projection data and B1_ID, the protocol session management system of the first device determines the highest priority data path from the first data path list. At this time, the first data path list only contains WLAN data paths, and the determined data path is the WLAN data path, which is then used to send the screen projection data.

[0290] S52, the protocol session management system of the first device sends a first transmission request to the transmitting and receiving system. The first transmission request carries screen projection data and information of the WLAN data path recorded in the first data path list (i.e., WLAN_IP2 and port S1).

[0291] S53, the transmitting system of the first device responds to the first transmitting request and transmits screen projection data to the transmitting and receiving system of the second device through the WLAN data path.

[0292] Specifically, the first device's sending and receiving system performs operations such as fragmenting, encrypting, and encapsulating protocol headers on the data packets to be sent in the screen projection data. It then obtains a list of first data paths, selects the highest priority data path (which is the WLAN data path), attaches the data packets to the selected path, and sends them to the second device.

[0293] S54, after receiving the projection data, the second device's sending and receiving system sends the projection data and port S1 to the protocol session management system.

[0294] It should be understood that the sending and receiving system can obtain the UDP port for receiving screen projection data, namely port S1.

[0295] S55, the protocol session management system of the second device determines the ID (i.e., B2_ID) of the second protocol session based on the port S1 that receives the screen projection data.

[0296] When creating a protocol session, the protocol session management system can store the protocol session ID and the port corresponding to that ID. Then, it can determine the ID of the second protocol session corresponding to port S1 based on the port S1 that receives service data.

[0297] S56, the protocol session management system of the second device sends screen projection data and B2_ID to the data path establishment system.

[0298] S57, the data path establishment system of the second device sends screen projection data and A2_ID to the business session management system.

[0299] The data path establishment system of the second device stores the correspondence between the ID of the second service session (i.e., A2_ID) and the ID of the second protocol session (i.e., B2_ID). Therefore, after the data path establishment system receives the projection data and A2_ID, it can determine the B2_ID corresponding to A2_ID, and then send the projection data and B2_ID to the protocol session management system.

[0300] S58, the service session management system of the second device sends the screen projection data and the ID of the second service session (i.e., A2_ID) to the screen projection application.

[0301] S59, the second device's screen mirroring application displays the screen mirroring data.

[0302] Similarly, after S46, the screen mirroring application on the second device can send service data of the second service session to the screen mirroring application on the first device. The specific implementation is the same as described above, where the screen mirroring application on the first device sends service data of the first service session to the screen mirroring application on the second device; it will not be repeated here.

[0303] S60, after the P2P physical connection is successfully established, the control path establishment system of the first device obtains the P2P IP address of the first device (represented as P2P_IP1) and the P2P IP address of the second device (represented as P2P_IP2) through the DHCP protocol.

[0304] S60 is executed after S07 successfully establishes the P2P physical connection.

[0305] S61, the control path establishment system of the first device performs a three-way handshake with the control path establishment system of the second device via P2P to create a P2P control path.

[0306] The three-way handshake requires the device to know the P2P IPs (i.e., P2P_IP1 and P2P_IP2) of both the local (first device) and the peer (second device). If the handshake is successful, the first device confirms that the P2P control path has been successfully established.

[0307] S62, after the P2P control path is successfully established (i.e., the three-way handshake is successful), the control path establishment system of the first device sends a second data path establishment request to the data path establishment system. The second data path establishment request carries the P2P IP of the first device (i.e., P2P_IP1), the P2P IP of the second device (i.e., P2P_IP2), and the ID of the first service session (i.e., A1_ID).

[0308] S63, in response to the second data path establishment request, the data path establishment system of the first device checks whether the ID of the first protocol session (i.e., B1_ID) corresponding to the ID of the first service session is valid. At this time, B1_ID is valid.

[0309] Since a first protocol session has already been created during the establishment of the WLAN data path, and the ID of the first protocol session is a valid value (i.e., B1_ID), S64 can be executed. Conversely, if it is invalid, it is necessary to create a protocol session corresponding to the first service session (i.e., the first protocol session), and then create the first protocol session. At this time, a session creation request can be sent to the protocol session management system of the first device to create the first protocol session.

[0310] S64, when the data path establishment system of the first device is valid, it sends a first port request instruction to the protocol session management system. The first port request instruction carries P2P_IP1 to indicate the port to be requested.

[0311] S65, the protocol session management system of the first device responds to the first port request instruction and requests a UDP port on the local P2P IP (i.e., P2P_IP1), which is exemplarily represented as port C2.

[0312] S66, the protocol session management system of the first device sends the ID (i.e., B1-ID) and port C2 of the first protocol session to the data path establishment system.

[0313] S67, the data path establishment system of the first device sends a third message to the data path establishment system of the second device. The third message carries port C2, the ID of the first service session (i.e., A1_ID) and the link type P2P, and is used to negotiate the establishment of a P2P data path.

[0314] S68, after receiving the third message, the data path establishment system of the second device parses the third message to obtain the port C2, A1_ID, link type P2P, and the P2P IPs (i.e., P2P_IP1 and P2P_IP2) of the first and second devices.

[0315] Specifically, the data path establishment system of the second device can parse the third message to obtain the port C2, A1_ID, and link type P2P carried in the third message. When the link type is P2P, the data path establishment system of the second device can obtain the source address (i.e., P2P_IP1) of the third message and the destination address (i.e., P2P_IP2) of the first message.

[0316] S69, the data path establishment system of the second device sends a fifth session creation request to the service session management system. The fifth session creation request carries the ID of the first service session and is used to request the creation of the protocol session corresponding to the first service session.

[0317] S70, the service session management system of the second device responds to the fifth session creation request by checking whether the local end contains the service session corresponding to the ID (i.e., A1_ID) of the first service session.

[0318] In the process of establishing a WLAN data path, the service session management system of the second device has already established a second service session corresponding to the ID of the first service session (i.e., A1_ID). Therefore, it is not necessary to create another one, and S71 can be executed. It should be understood that if the ID is not present, the service management system of the second device needs to create the second service session.

[0319] S71, the service session management system of the second device returns fourth information to the data path establishment system. The fourth information includes the ID of the second service session (i.e., A2_ID), which is used to indicate that the second service session has been created.

[0320] S72, after receiving the fourth information, the data path establishment system of the second device can check whether the ID of the second protocol session corresponding to the second service session is valid.

[0321] The second protocol session is also created when the WLAN data path is established. At this time, the ID of the second protocol session is valid. It should be understood that if the ID of the second protocol session is invalid, then the second protocol session needs to be created again.

[0322] S73, when the data path establishment system of the second device is valid, the second protocol session ID sends a second port request instruction to the protocol session management system. The second port request instruction carries the P2P IP (i.e., P2P_IP2) of the second device and is used to request a UDP port on P2P_IP2.

[0323] S74, the protocol session management system of the second device requests a UDP port on the local P2P IP (i.e., P2P_IP2), which is exemplarily represented as port S2.

[0324] S75, the protocol session management system of the second device sends the system port S2 and the ID of the second protocol session (i.e., B2_ID) to the data path establishment system.

[0325] S76, the data path establishment system of the second device sends a third response message to the data path establishment system of the first device. The third response message is a response message of the third message, carrying the ID of the first service session (i.e., A1_ID), the ID of the second service session (i.e., A2_ID), the link type P2P and the port S2.

[0326] The data path establishment system for the second device can determine the ID of the corresponding second service session (i.e., A2_ID) based on the ID of the second protocol session (i.e., B2_ID), and then determine the ID of the first service session (i.e., A1_ID) corresponding to that A2_ID.

[0327] S77, after receiving the third response message, the data path establishment system of the first device sends a second protocol connection instruction to the protocol session management system. The second protocol connection instruction carries the P2P IP (i.e., P2P_IP2), port S2 and the ID of the first protocol session (i.e., B1_ID) of the second device.

[0328] The data path establishment system of the first device can parse the third response message to obtain the A1_ID, A2_ID and port S2 carried by it. Furthermore, based on the ID of the first service session (i.e. A1_ID), the ID of the first protocol session, i.e. A1_ID, can be obtained.

[0329] S78, the protocol session management system of the first device responds to the second protocol connection command and performs a protocol handshake with the protocol session management system of the second device to exchange their respective protocol session IDs.

[0330] Specifically, the protocol session management system of the first device sends a fourth message to the protocol session management system of the second device, which carries the ID of the first protocol session. After receiving the fourth message, the protocol session management system of the second device sends a fourth response message to the protocol session management system of the second device, which carries the ID of the second protocol session. At this point, the handshake is completed.

[0331] S79, the protocol session management system of the first device adds a P2P data path to the first data path list.

[0332] Specifically, a P2P data path is added to the first data path list, that is, the information of the P2P data path corresponding to B1_ID is added. The recorded P2P data path information may include the peer's P2P IP and port, such as P2P_IP2 and port S2. At this time, the first data path list includes P2P data paths and WLAN data paths, with P2P data paths having higher priority than WLAN data paths.

[0333] S80, the protocol session management system of the first device sends the ID (i.e., B1_ID) of the first protocol session and the link type P2P to the data path establishment system.

[0334] S81, the data path establishment system of the first device sends the ID (i.e., A1_ID) of the first business session and the link type P2P to the business session management system.

[0335] S82, the service session management system of the first device adds a P2P data path to the list of third data paths corresponding to the ID of the first service session.

[0336] The information on P2P data paths included in the third data path list may include the link type P2P.

[0337] S83, the service session management system of the first device checks whether the available flag of the first service session is valid. If it is valid, the first notification is not sent.

[0338] At this point, the available flag is valid (true), and it is no longer necessary to send the first notification to inform the screen mirroring application that the first business session has been successfully opened or that the business data of the first business session can be transmitted.

[0339] Accordingly, after S78, the second device can also perform the same operations as S79-S83 described above, as detailed in steps S84-S88 below.

[0340] S84, the protocol session management system of the second device adds a P2P data path to the second data path list.

[0341] Specifically, a P2P data path is added to the second data path list, that is, the information of the P2P data path corresponding to B2_ID is added. The recorded P2P data path information can include the peer's P2P IP and port, such as P2P_IP1 and port C2. At this time, the second data path list includes P2P data paths and WLAN data paths, with P2P data paths having higher priority than WLAN data paths.

[0342] S85, the protocol session management system of the second device sends the ID of the second protocol session (i.e., B1_ID) and the link type P2P to the data path establishment system.

[0343] S86, the data path establishment system of the second device sends the ID (i.e., A1_ID) of the second service session and the link type P2P to the service session management system.

[0344] S87, the service session management system of the second device adds a P2P data path to the fourth data path list corresponding to the ID of the second service session.

[0345] The information on the P2P data paths included in the fourth data path list may include the link type P2P.

[0346] S88, the service session management system of the second device checks whether the available flag of the second service session is valid. If it is valid, the second notification is not sent.

[0347] At this point, the available flag is valid (true), and there is no longer a need to send a second notification to inform the screen mirroring application that the second business session has been successfully opened or that the business data of the second business session can be transmitted.

[0348] It should be understood that S80-S82 and S85-S87 are not mandatory steps. In some embodiments, the device's service session management system may not include the data path list corresponding to the service session, and it may not be necessary to check whether the available flag of the service session is valid.

[0349] Following S79, the specific implementation of the screen mirroring data that the screen mirroring application of the first device can send to the screen mirroring application of the second device can be as follows: Figure 5E As shown, including but not limited to some or all of the following steps:

[0350] S89, after receiving the first notification, the screen mirroring application of the first device can send the business data (i.e., screen mirroring data) of the first business session and the ID (i.e., A1_ID) of the first business session to the business session management system.

[0351] S90, after receiving the projection data and the ID of the first service session, the service session management system of the first device sends the projection data and the ID of the first service session (i.e., A1_ID) to the data path establishment system.

[0352] S91, the data path establishment system of the first device sends the screen projection data and the ID of the first protocol session (i.e., B1_ID) to the protocol session management system.

[0353] The data path establishment system of the first device stores the correspondence between the ID of the first service session (i.e., A1_ID) and the ID of the first protocol session (i.e., B1_ID). Therefore, after the data path establishment system receives the projection data and A1_ID, it can determine the B1_ID corresponding to A1_ID, and then send the projection data and B1_ID to the protocol session management system.

[0354] S92, after receiving the screen projection data and B1_ID, the protocol session management system of the first device determines the highest priority data path from the first data path list. At this time, the first data path list includes WLAN data paths and P2P data paths, and the determined data path is the P2P data path, which is used to send the screen projection data.

[0355] S93, the protocol session management system of the first device sends a second sending request to the sending and receiving system. The second sending request carries the screen projection data and the information of the P2P data path recorded in the first data path list (i.e., P2P_IP2 and port S2).

[0356] S94, the transmitting system of the first device responds to the second transmitting request and transmits the screen projection data to the transmitting and receiving system of the second device through the P2P data path.

[0357] Specifically, the sending and receiving system of the first device performs operations such as fragmentation, encryption, and encapsulation of protocol headers on the data packets to be sent in the screen projection data, further obtains the first data path list, selects the highest priority data path, which is the P2P data path, attaches the data packets to the selected path, and sends them to the second device.

[0358] S95, after the second device's sending and receiving system receives the screen projection data, it sends the screen projection data and port S1 to the protocol session management system.

[0359] It should be understood that the sending and receiving system can obtain the UDP port for receiving screen projection data, namely port S2.

[0360] S96, the protocol session management system of the second device determines the ID (i.e., B2_ID) of the second protocol session based on the port S2 that receives the screen projection data.

[0361] When creating a protocol session, the protocol session management system can store the protocol session ID and the port corresponding to that ID. Then, it can determine the ID of the second protocol session corresponding to port S2 based on the port S2 that receives service data.

[0362] S97, the protocol session management system of the second device sends the projection data and B2_ID to the data path establishment system.

[0363] S98, the data path establishment system of the second device sends screen projection data and A2_ID to the business session management system.

[0364] The data path establishment system of the second device stores the correspondence between the ID of the second service session (i.e., A2_ID) and the ID of the second protocol session (i.e., B2_ID). Therefore, after the data path establishment system receives the projection data and A2_ID, it can determine the B2_ID corresponding to A2_ID, and then send the projection data and B2_ID to the protocol session management system.

[0365] S99, the service session management system of the second device sends the screen projection data and the ID of the second service session (i.e., A2_ID) to the screen projection application.

[0366] S100, the second device's screen mirroring application displays the screen mirroring data.

[0367] like Figure 6B As shown, the display interface 62 of the second device includes the interface 61 currently displayed by the first device.

[0368] Similarly, after S84, the screen mirroring application on the second device can send service data of the second service session to the screen mirroring application on the first device. The specific implementation is the same as described above, where the screen mirroring application on the first device sends service data of the first service session to the screen mirroring application on the second device; it will not be repeated here.

[0369] In the above method, when the first device initiates a data transmission service session to the second device, it simultaneously triggers a WLAN connection and a P2P connection. Before the P2P connection is successfully established, the service data of the service session is transmitted through the WLAN data path. After the P2P connection is successfully established, the service data is switched to the P2P data path to reduce the user's waiting time.

[0370] Example 2

[0371] Example 2 provides a method for device communication when a P2P link is abnormally disconnected. When the P2P link is abnormally disconnected, service data can be dynamically switched to a WLAN link, and a reconnection and recovery of the P2P connection can be initiated. Before the P2P link is restored, service data is transmitted via WLAN. After the P2P reconnection is successful, service data is switched back to the P2P link. This ensures that service data transmission is not interrupted when the P2P link is abnormally disconnected.

[0372] like Figure 7 As shown, the device communication method when the P2P link is abnormal may include, but is not limited to, some or all of the following steps:

[0373] S101, the control path establishment system of the first device detects whether the P2P physical connection with the second device is faulty. If faulty, S102-S106 can be executed to switch the screen projection data to the WLAN data path, or S107-S114 can be executed to trigger the P2P connection reconstruction so that the screen projection data can be transmitted through the newly created P2P data channel after reconstruction.

[0374] S102, when the control path establishment system of the first device detects the P2P physical connection failure, it sends a third notification to the protocol session management system. The third notification carries the ID of the first protocol session and is used to indicate that the P2P data path corresponding to the ID of the first protocol session has failed.

[0375] S103, the protocol session management system of the first device deletes the P2P data path from the first data path list so that the WLAN data channel can be used for subsequent screen projection data transmission.

[0376] Specifically, the protocol session management system of the first device can first determine the data path list corresponding to the ID of the first protocol session (i.e., the first data path list), and then delete the P2P data path from the first data path list, that is, delete P2P_IP2 and port S2.

[0377] S104, when the protocol session management system of the first device receives the screen projection data and the ID (B1_ID) of the first service session from the data path establishment system after S103, it determines the WLAN data path as the highest priority data path from the first data path list.

[0378] After S103, the first data path list includes WLAN data paths but does not include P2P data paths. The protocol session management system of the first device determines the WLAN data path as the highest priority data path from the first data path list.

[0379] S105, the protocol session management system of the first device sends a third transmission request to the transmitting and receiving system. The third transmission request carries screen projection data and information of the WLAN data path recorded in the first data path list (i.e., WLAN_IP2 and port S1).

[0380] S106, the transmitting system of the first device responds to the third transmitting request and transmits screen projection data to the transmitting and receiving system of the second device through the WLAN data path.

[0381] The specific implementation of S104-S106 can be found in S51-S53 above. The second device can execute steps S54-S59, which will not be repeated here.

[0382] S107, when the control path establishment system of the first device detects the P2P physical connection failure, it sends an indication message to the service session management system. The indication message carries the ID of the first service session to indicate the P2P data link failure corresponding to the first service session.

[0383] S108: After receiving the instruction information, the service session management system of the first device can determine whether to perform P2P reconnection. If yes, then execute S109; otherwise, no operation is required to use the WLAN data path to transmit the screen projection data, or to close the first service session.

[0384] The service session management system of the first device can decide whether to reconnect. It can determine the cause of the fault. For example, if the fault is caused by the user triggering the closure of the P2P connection, then P2P reconnection is not required. Or, if the fault is caused by insufficient memory of the first device or poor current communication quality, then S109 can be executed to trigger P2P reconnection.

[0385] Optionally, the business session management system of the first device can also delete the P2P data path from the third data path list.

[0386] S109, the service session management system of the first device sends a P2P reconnection request to the control path establishment system. The request carries MAC1 and MAC2 to request a P2P connection.

[0387] S110, the control path establishment system of the first device and the control path establishment system of the second device perform P2P connection reconstruction to establish P2P physical connection, P2P control path and P2P data path.

[0388] It should be understood that the process of P2P connection reconstruction includes the P2P physical connection between the first device and the second device, the creation of the P2P control path, the creation of the P2P data path, etc. The specific implementation of reconstruction S107 can be found in S07, S60-S78 above, and will not be repeated here.

[0389] It should be noted that during the reconstruction process, when S60 is executed, the P2P IP of the first device obtained is different from the P2P_IP1 of the first device mentioned above. Similarly, the P2P IP of the second device obtained is also different from the P2P_IP2 of the second device mentioned above. For example, the P2P IP of the first device and the P2P IP of the second device obtained during the reconstruction process are represented as P2P_IP3 and P2P_IP4, respectively.

[0390] Similarly, during the reconstruction process, when S65 is executed, the UDP port number requested in P2P_IP3 will also change, and will be represented as port C3; when S74 is executed, the UDP port number requested in P2P_IP4 will also change, and will be represented as port S3.

[0391] S111, after the P2P reconnection is successful, the protocol session management system of the first device adds the newly created P2P data path to the first data path list, that is, adds P2P_IP4 and port S3.

[0392] S112, when the protocol session management system of the first device receives the projection data and the ID (B1_ID) of the first service session from the data path establishment system after S112, it determines the newly created P2P data path as the highest priority data path from the first data path list.

[0393] After S112, the first data path list includes WLAN data paths and recreated P2P data paths. The protocol session management system of the first device determines the recreated P2P data path as the highest priority data path from the first data path list.

[0394] S113, the protocol session management system of the first device sends a fourth transmission request to the sending and receiving system. The fourth transmission request carries the screen projection data and the information of the newly created P2P data path recorded in the first data path list (i.e., P2P_IP4 and port S3).

[0395] S114, the first device's transmitting system responds to the fourth transmitting request by sending the projection data to the second device's transmitting and receiving system through the re-created P2P data path.

[0396] In the process of sending screen projection data from the first device to the second device after S103 but before the P2P connection reconnection is successful, the process is the same as described in S48-S59. After the P2P connection reconnection is successful, the process of sending screen projection data from the first device to the second device is in principle the same as described in S89-S100, but a newly created P2P data path is used. It should be understood that during the P2P reconnection process, the second device will also add the newly created P2P data path to the second data path list, that is, add P2P_IP3 and port C3, so as to use the newly created P2P data path to transmit the service data of the second service session. The process of the second device sending the service data of the second service session to the first device is in principle the same as the process of the first device sending screen projection data to the second device described above, and will not be repeated here.

[0397] Example 3

[0398] Example 3 provides a device communication method that can simultaneously trigger WLAN and P2P connections when a first device initiates a first service session for data transmission to a second device. Before the P2P connection is successful, the service data of the first service session is sent to the second device via WLAN. After the P2P connection is successful, the service data is sent to the second device via P2P, thereby switching the service data to the P2P link and reducing the user's waiting time.

[0399] like Figure 8 The diagram illustrates the device communication method provided in Embodiment 3. This method can be derived from the above... Figure 1 The system implementation shown may include, but is not limited to, some or all of the following steps:

[0400] S201, the application of the first device receives a user operation to send first data to the second device.

[0401] In step S201, the first device and the second device are each connected to the same access point (AP) via WLAN. User operation can include screen mirroring to the second device; in this case, the mirrored data is the same as the first data. For specific implementation details, please refer to the above. Figure 5AIn S01, the user operation can also be a user operation shared with the second device during a call. In this case, the call data collected by the first device is the first data. The user operation can also be a user operation shared with the second device via keyboard and mouse. In this case, the service data of the first service session is the control data received by the first device via the keyboard or mouse, etc.

[0402] S202, The first device creates the first service session.

[0403] The first service session is used to transmit the first data. The service data of the first service session is the first data.

[0404] Specifically, the first device creates a first service session, generates an ID for the first service session, and initializes the ID of the protocol session (i.e., the first protocol session) corresponding to the first service session to an invalid value. For details on the implementation, please refer to the above. Figure 5A S04 in the middle.

[0405] Optionally, the first device may also set the available flag of the first service session to invalid.

[0406] Optionally, between S202 and S203, the first device may obtain the WLAN IP and MAC of the second device (i.e., WLAN_IP2 and MAC2).

[0407] S203, the first device performs a three-way handshake using the TCP protocol with the second device via WLAN to establish a WLAN control path. See the above for details. Figure 5A S06 in the text will not be elaborated upon here.

[0408] S204, the first device and the second device establish a P2P physical connection. See the above for details on the implementation. Figure 5A S07 in the text will not be elaborated upon here.

[0409] The first device can trigger S203 and S204 simultaneously.

[0410] S205, after the first device establishes the WLAN control path, it negotiates with the second device to establish a WLAN data path through the WLAN control path.

[0411] like Figure 9A As shown, a specific implementation of S205 may include, but is not limited to, the following steps:

[0412] S205a, The first device creates the first protocol session corresponding to the first service session.

[0413] S205b, the first device applies for UPD port C1 on its local WLAN IP.

[0414] S205c, the first device sends a first message to the second device. The first message carries port C1, the ID of the first service session and the link type WLAN, and is used to negotiate the WLAN data path for the first service session.

[0415] S205d, the second device parses the first packet to obtain port C1, the ID of the first service session, the link type WLAN, and the WLAN IPs of the first and second devices.

[0416] S205e, the second device creates a second service session if it does not contain a service session corresponding to the first service session, and creates a second protocol session if the ID of the protocol session corresponding to the second service session is invalid.

[0417] In one specific implementation of S205e, the second device can first check whether it contains a service session corresponding to the first protocol session. If not, it creates the service session corresponding to the first service session (i.e., creates the second service session); if so, it does not need to create the second service session. Furthermore, the second device can check whether the ID of the protocol session corresponding to the second service session is valid. If not, it creates the protocol session corresponding to the second service session (i.e., creates the second protocol session). Otherwise, it does not need to create the second protocol session. See the above for a detailed implementation. Figure 5B S20-S25 in the above will not be elaborated here.

[0418] S205f: The second device requests UPD port S1 on the local WLAN IP. For specific implementation details, please refer to the above. Figure 5B S26 in the text will not be elaborated here.

[0419] S205g, the second device sends a first response message to the first device. The first response message carries the port S1, the ID of the first service session, the ID of the second service session, and the link type WLAN.

[0420] After receiving the first response message, the second device parses the first response message, obtains the port S1, the ID of the first service session, the ID of the second service session, and the link type WLAN, and executes S205h.

[0421] In step S205h, the first device and the second device perform a protocol handshake to exchange their respective protocol session IDs. For details, please refer to the above. Figure 5B S33 in the text will not be elaborated here.

[0422] S206, the first device adds a WLAN data path to the first data path list corresponding to the first protocol session. For specific implementation details, please refer to the above. Figure 5B S34 in the text will not be elaborated here.

[0423] S207, the second device adds a WLAN data path to the second data path list corresponding to the second protocol session. For specific implementation details, please refer to the above. Figure 5B S41 in the above will not be elaborated here. Optionally, after S206, the first device can also check whether the availability flag of the first service session is valid. If it is valid, it determines that the service data of the first service session can be sent; if it is invalid, it modifies the validity flag of the first service session to be valid. For specific implementation, please refer to the above. Figure 5B Steps S38-S40. Similarly, after S207, the second device can also check whether the availability flag of the second service session is valid. If valid, it determines that the service data of the second service session can be sent; if invalid, it modifies the validity flag of the second service session to be valid. For specific implementation details, please refer to the above. Figure 5B Steps S45-S47.

[0424] S208, when the first device receives service data of the first service session, it determines the data path with the highest priority as the WLAN data path from the first data path list.

[0425] Before a P2P connection is successfully established, the first data path list includes WLAN data paths but does not include P2P data paths. At this time, the data path with the highest priority is the WLAN data path.

[0426] S209, the first device sends the service data of the first service session to the second device through the highest priority link (WLAN link).

[0427] For specific implementation details of S208-S209, please refer to the above. Figure 5C This will not be elaborated upon here.

[0428] It should be understood that after S207, the specific implementation of the second device sending the service data of the second service session to the first device is the same as the first device sending the service data of the first service session to the second device. Specifically, when the second device receives the service data of the second service session, it determines the data path with the highest priority as the WLAN data path from the second data path list, and sends the service data of the second service session to the first device through the WLAN data path.

[0429] S210, the first device confirms that the P2P physical connection is successful.

[0430] Optionally, after the P2P physical connection is successfully established, the first device can also obtain the IP addresses of the first device and the second device via the DHCP protocol. For specific implementation details, please refer to the above. Figure 5D The S60 in this context will not be discussed further here.

[0431] S211, the first device performs a three-way handshake using the TCP protocol with the second device via P2P to establish a P2P control path. See the above for details on the implementation. Figure 5D The S61 in the text will not be elaborated upon here.

[0432] S212, the first device negotiates with the second device to establish a P2P data path through the P2P control path.

[0433] Among them, such as Figure 9B As shown, a specific implementation of S212 may include some or all of the following steps S212a-S212f:

[0434] S212a, the first device applies for UPD port C2 on its local P2P IP.

[0435] Since the first service session and the first protocol session have already been created at this point, the first device can execute S212a to avoid duplicate creation. Optionally, before executing S212a, the first device can also check whether the ID of the first protocol session is valid. If it is valid, S212a is executed; otherwise, if it is invalid, the first protocol session needs to be created before executing S212a. For specific implementation details, please refer to the above. Figure 5D S62-S66 in the above will not be elaborated here.

[0436] S212b, the first device sends a second message to the second device. This message carries port C2, the first service session ID, and the link type P2P, and is used to negotiate a P2P data path for the first service session. For specific implementation details, please refer to the above. Figure 5D The S67 in the text will not be elaborated upon here.

[0437] S212c, the second device parses the second packet to obtain port C2, the ID of the first service session, and the link type P2P, as well as the P2P IP of the first device and the P2P IP of the second device. For specific implementation details, please refer to the above. Figure 5D The S68 in the text will not be discussed further here.

[0438] S212d, the second device applies for UPD port S2 on the local P2P IP.

[0439] Since the second service session and the second protocol session have already been created at this point, the second device can execute S212d to avoid duplicate creation. Optionally, after S212c and before S212d, the second device can also check whether it contains a service session corresponding to the first service session. If so, it does not need to create the second protocol session; otherwise, it needs to be created. Furthermore, the second device can also check whether the ID of the second protocol session corresponding to the second service session is valid. If valid, it executes S212d; otherwise, if invalid, it needs to create the second protocol session before executing S212d. For specific implementation details, please refer to the above. Figure 5D S69-S75 in the document will not be elaborated here.

[0440] S212e, the second device sends a second response message to the first device. This first response message carries port S2, the first service session ID, the second service session ID, and the link type P2P. For specific implementation details, please refer to the above. Figure 5D The S76 in the text will not be discussed further here.

[0441] In step S212f, the first device and the second device perform a protocol handshake to exchange their respective protocol session IDs. For details, please refer to the above. Figure 5D S77-S78 in the text will not be elaborated here.

[0442] S213, the first device adds a P2P data path to the first data path list. For specific implementation details, please refer to the above. Figure 5D The S79 in the text will not be elaborated upon here.

[0443] S214, the second device adds a P2P data path to the second data path list. See the above for details on the implementation. Figure 5D The S84 in the text will not be discussed further here.

[0444] Optionally, after S213, the first device can also check whether the availability flag of the first service session is valid. If it is valid, it determines that the service data of the first service session can be sent. If it is invalid, it modifies the validity flag of the first service session to be valid. For specific implementation, please refer to the above. Figure 5D In step S83. Similarly, after S214, the second device can also check whether the availability flag of the second service session is valid. If it is valid, it determines that the service data of the second service session can be sent; if it is invalid, it modifies the validity flag of the second service session to be valid. For specific implementation details, please refer to the above. Figure 5D Steps S86-S88.

[0445] S215, when the first device receives the service data of the first service session, it determines the data path with the highest priority as the P2P data path from the first data path list.

[0446] After a successful P2P connection, the first data path list includes both WLAN data path and P2P data path, with the P2P data path having the highest priority.

[0447] S216, the first device sends the service data of the first service session to the second device through the P2P data path.

[0448] The specific implementations of S215-S216 can be found above. Figure 5E This will not be elaborated upon here.

[0449] It should be understood that after S214, the specific implementation of the second device sending the service data of the second service session to the first device is the same as the first device sending the service data of the first service session to the second device. Specifically, when the second device receives the service data of the second service session, it determines the data path with the highest priority as the P2P data path from the second data path list, and sends the service data of the second service session to the first device through the P2P data path.

[0450] A specific implementation of S201-S216 above can be found in the above... Figures 5A-5E This will not be elaborated upon here.

[0451] Example 4

[0452] Example 4 provides a method for device communication when a P2P physical connection is abnormally disconnected. It also allows for dynamic switching of service data to the WLAN data path when the P2P link is abnormally disconnected, and initiates P2P connection reconnection and recovery. Before the P2P connection is restored, service data is transmitted via WLAN. After successful P2P reconnection, service data is switched back to the P2P data path. This ensures that service data transmission is not interrupted when the P2P physical connection is abnormally disconnected.

[0453] like Figure 10 As shown, the device communication method when the P2P link is abnormal may include, but is not limited to, some or all of the following steps:

[0454] S301, the first device detects whether the P2P physical connection is faulty. For details, please refer to the above. Figure 7 S101, which will not be discussed further here.

[0455] S302, the first device deletes the P2P data path from the first data path list. For details, please refer to the above. Figure 7S102-S103 will not be elaborated here.

[0456] S303: Before the P2P connection is successfully established, the first device sends the service data of the first service session to the second device through the WLAN data path. For details, please refer to the above. Figure 7 S104-S106 will not be elaborated here.

[0457] S304, the first device and the second device establish a P2P physical connection.

[0458] S305, the first device confirms that the P2P physical connection is successful.

[0459] S306, the first device establishes a P2P control path by performing a three-way handshake with the second device using the TCP protocol.

[0460] S307, the first device negotiates with the second device to establish a P2P data path through the P2P control path.

[0461] It should be noted that the specific implementations of S304-S307 are the same as those described above. Figure 5D The difference between S60-S78 is that the P2P IPs used at both ends of the recreated P2P control channel, and the P2P IPs and port numbers involved in the recreated P2P data channel, will change. See the above for specific implementation details. Figure 7 The S110 is not discussed further here.

[0462] S308, the first device adds the newly created P2P data path to the first data path list. For details, please refer to the above. Figure 7 S111, which will not be elaborated on here.

[0463] S309, when the first device receives service data from the first service session, it determines the highest priority data path from the first data path list as the newly created P2P data path. For details, please refer to the above. Figure 7 S112, which will not be discussed further here.

[0464] S310: After the P2P connection is successfully established, the first device sends the service data of the first service session to the second device through the P2P data path. For details, please refer to the above. Figure 7 S113-S114 will not be elaborated here.

[0465] A specific implementation of S301-S310 above can be found in the above... Figure 7 This will not be elaborated upon here.

[0466] It should be understood that the steps in the above-described method embodiments provided in this application can be implemented by integrated logic circuits in the processor hardware or by instructions in software form. The method steps disclosed in the embodiments of this application can be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules in the processor.

[0467] This application also provides an electronic device that may include a memory and a processor. The memory may be used to store a computer program; the processor may be used to invoke the computer program in the memory to cause the electronic device to perform the methods in any of the above embodiments.

[0468] This application also provides a chip system including at least one processor for implementing the functions involved in the methods performed by the electronic device in any of the above embodiments.

[0469] In one possible design, the chip system also includes a memory for storing program instructions and data, which may be located inside or outside the processor.

[0470] The chip system can consist of chips or include chips and other discrete components.

[0471] Optionally, the chip system may contain one or more processors. These processors can be implemented in hardware or software. When implemented in hardware, the processor can be a logic circuit, an integrated circuit, etc. When implemented in software, the processor can be a general-purpose processor, implemented by reading software code stored in memory.

[0472] Optionally, the chip system may contain one or more memories. The memory may be integrated with the processor or disposed separately from it; this application embodiment does not limit this. For example, the memory may be a non-transient processor, such as a read-only memory (ROM), which may be integrated with the processor on the same chip or disposed separately on different chips. This application embodiment does not specifically limit the type of memory or the arrangement of the memory and processor.

[0473] For example, the chip system may be a field programmable gate array (FPGA), an application specific integrated circuit (ASIC), a system on chip (SoC), a central processor unit (CPU), a network processor (NP), a digital signal processor (DSP), a micro controller unit (MCU), a programmable logic device (PLD), or other integrated chips.

[0474] This application also provides a computer program product, which includes a computer program (also referred to as code or instructions) that, when run, causes a computer to perform the method executed by the electronic device in any of the above embodiments.

[0475] This application also provides a computer-readable storage medium storing a computer program (also referred to as code or instructions). When the computer program is run, it causes the computer to perform the method executed by the electronic device in any of the above embodiments.

[0476] The various embodiments of this application can be combined arbitrarily to achieve different technical effects.

[0477] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product. A computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the flow or function according to this application is generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state disk).

[0478] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. This program can be stored in a computer-readable storage medium, and when executed, it can include the processes described in the above method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as ROM or random access memory (RAM), magnetic disks, or optical disks.

[0479] In summary, the above are merely embodiments of the technical solution of the present invention and are not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made according to the disclosure of the present invention should be included within the scope of protection of the present invention.

Claims

1. A device communication method, characterized in that, Applied to a first electronic device, the method includes: In response to a received user operation to send first data to a second electronic device, the first electronic device initiates the establishment of a wireless local area network (WLAN) connection with the second electronic device and a peer-to-peer (P2P) connection with the second electronic device. The first electronic device and the second electronic device are respectively connected to the same wireless access point via WLAN. After the first electronic device successfully establishes the WLAN connection with the second electronic device, but before the first electronic device successfully establishes the P2P connection with the second electronic device, it sends the first data to the second electronic device through the WLAN connection; After the first electronic device successfully establishes the P2P connection with the second electronic device, it sends the first data to the second electronic device through the P2P connection. The method further includes: before establishing a WLAN control path with the second electronic device, the first electronic device creates a first service session, the first service session is used to transmit the first data, and the identifier of the first protocol session corresponding to the first service session is set to an invalid value; The establishment of a wireless local area network (WLAN) connection with the second electronic device includes: when the first electronic device creates a WLAN data path with the second electronic device, if the identifier of the first protocol session is invalid, creating the first protocol session and updating the identifier of the first protocol session to a valid value; requesting a third port on the WLAN IP of the first electronic device; sending a first message to the second electronic device, the first message carrying the identifier of the first service session, the third port, and the first link type; receiving a first response message from the second electronic device, the first response message carrying the identifier of the first service session, the identifier of the second service session, the first port, and the first link type; the second service session is a service session created by the second electronic device corresponding to the first service session; the first port is the port of the WLAN IP of the second electronic device; The establishment of a point-to-point (P2P) connection with the second electronic device includes: when the first electronic device creates a P2P data path with the second electronic device, checking whether the identifier of the first protocol session is valid; if the identifier of the first protocol session is valid, requesting a fourth port on the P2P IP of the first electronic device; sending a third message to the second electronic device, the third message carrying the identifier of the first service session, the fourth port, and the second link type; and receiving a third response message from the second electronic device, the third response message carrying the identifier of the first service session, the identifier of the second service session, the second port, and the second link type, wherein the second port is the port of the P2P IP of the second electronic device.

2. The method according to claim 1, characterized in that, The method further includes: After the first electronic device successfully establishes the WLAN connection, it adds WLAN data path information to the first data path list. The WLAN data path information includes the WLAN IP and the first port of the second electronic device. After the P2P connection is successfully established, the first electronic device adds P2P data path information to the first data path list. The P2P data path information includes the P2P IP and the second port of the second electronic device.

3. The method according to claim 2, characterized in that, The P2P data path has a higher priority than the WLAN data path, and the priority is used to determine the data path for sending the first data.

4. The method according to claim 2 or 3, characterized in that, The method further includes: When the P2P connection fails, the first electronic device deletes the information of the P2P data path from the first data path list, sends the first data to the second electronic device through the WLAN connection, and triggers the re-establishment of the P2P connection with the second electronic device.

5. The method according to any one of claims 1-3, characterized in that, Establishing a WLAN connection with the second electronic device includes: The first electronic device establishes a WLAN control path with the second electronic device; The first electronic device establishes a WLAN data path with the second electronic device through the WLAN control path.

6. The method according to claim 1, characterized in that, The method further includes: After creating the first service session, the first electronic device sets the available flag of the first service session to invalid.

7. The method according to claim 6, characterized in that, After the first electronic device adds WLAN data path information or P2P data path information to the first data path list, the method further includes: updating the available flag bit to a valid value when the available flag bit of the first service session is set to invalid.

8. The method according to any one of claims 1-3 and 6-7, characterized in that, Establishing a P2P connection with the second electronic device includes: The first electronic device establishes a P2P physical connection with the second electronic device; After the first electronic device successfully establishes the P2P physical connection, it establishes a P2P control path with the second electronic device. The first electronic device establishes a P2P data path with the second electronic device through the P2P control path.

9. The method according to claim 6, characterized in that, The first electronic device includes an application program, a business session management system, and a control path establishment system; The creation of the first service session specifically includes: in response to receiving a first session creation request, the service session management system creates the first service session and generates an identifier for the first service session; Setting the available flag of the first service session to invalid and setting the identifier of the first protocol session corresponding to the first service session to an invalid value specifically includes: the service session management system sets the available flag of the first service session to invalid and sets the identifier of the first protocol session corresponding to the first service session to an invalid value. The available flag of the first service session is used to indicate whether the application has been notified to transmit the first data. Before the WLAN connection is successfully established, the available flag of the first service session is invalid; setting the identifier of the first protocol session to an invalid value indicates that the first protocol session has not been established.

10. The method according to claim 1, characterized in that, The first electronic device includes a service session management system and a control path establishment system, and the method further includes: The service session management system sends a connection request to the control path establishment system. The connection request carries the WLAN IP of the first electronic device, the WLAN IP of the second electronic device, the MAC of the first electronic device, and the MAC of the second electronic device. The connection request is used to request the establishment of a WLAN connection and a P2P connection with the second electronic device. The initiation of establishing a wireless local area network (WLAN) connection with the second electronic device and establishing a peer-to-peer (P2P) connection with the second electronic device specifically includes: the control path establishment system responding to the connection request by initiating the establishment of a WLAN control path with the second electronic device based on the WLAN IP of the first electronic device and the WLAN IP of the second electronic device, and establishing a P2P physical connection with the second electronic device based on the MAC of the first electronic device and the MAC of the second electronic device.

11. The method according to claim 1, characterized in that, The first electronic device includes a control path establishment system, a data path establishment system, and a protocol session management system; Before the first electronic device creates the first protocol session and updates the identifier of the first protocol session to a valid value when the identifier of the first protocol session is invalid, the method further includes: after the control path establishment system completes the establishment of the WLAN control path, the control path establishment system sends a first data path creation request to the data path establishment system. The first data path creation request carries the WLAN IP of the first electronic device, the WLAN IP of the second electronic device, and the identifier of the first service session. The first data path creation request is used to request the creation of the WLAN data path. When the identifier of the first protocol session is invalid, the first electronic device creates the first protocol session, specifically including: the data path establishment system responding to the first data path creation request, when the identifier of the first protocol session is invalid, sending a second session creation request to the protocol session management system, the second session creation request carrying the WLAN IP of the first electronic device, the second session creation request being used to request the creation of the first protocol session; the protocol session management system responding to the second session creation request, creating the first protocol session, generating an identifier for the first protocol session, the first protocol session being used to encapsulate and send the first data according to the requirements of the protocol.

12. The method according to claim 11, characterized in that, The first electronic device further includes a service session management system. The process of applying for a third port on the WLAN IP of the first electronic device is performed by the protocol session management system. After the first electronic device applies for a third port on the WLAN IP of the first electronic device, the method further includes: the protocol session management system sending the identifier of the first protocol session and the port number of the third port to the data path establishment system. Updating the identifier of the first protocol session to a valid value specifically includes: The data path establishment system sends the identifier of the first protocol session to the business session management system; In response to receiving the identifier of the first protocol session, the service session management system updates the identifier of the first protocol session to a valid value.

13. The method according to claim 7, characterized in that, The first electronic device includes a service session management system, a data path establishment system, and a protocol session management system; updating the available flag bit to a valid value specifically includes: The protocol session management system sends the identifier of the first protocol session to the business session management system through the data path establishment system; In response to receiving the identifier of the first service session, the service session management system sends a first notification to the application when the available flag of the first service session is invalid. The first notification carries the identifier of the first service session and is used to indicate the transmission of the first data. After sending the first notification, the business session management system sets the available flag of the first business session to be valid.

14. The method according to claim 1, characterized in that, The first electronic device includes a control path establishment system, a data path establishment system, and a protocol session management system; The method further includes: after the P2P control path is established, the control path establishment system sends a second data path creation request to the data path establishment system. The second data path creation request carries the P2P IP of the first electronic device, the P2P IP of the second electronic device, and the identifier of the first service session. The second data path creation request is used to request the creation of the P2P data path. The first electronic device checks whether the identifier of the first protocol session is valid, specifically including: the data path establishment system responds to the second data path creation request and checks whether the identifier of the first protocol session corresponding to the first service session is valid; When the identifier of the first protocol session is valid, the first electronic device applies for a fourth port on the P2P IP of the first electronic device. Specifically, when the identifier of the first protocol session is valid, the data path establishment system sends a first port application instruction to the protocol session management system. The first port application instruction carries the P2P IP of the second electronic device. In response to the first port request instruction, the protocol session management system requests a fourth port on the P2P IP of the first electronic device.

15. The method according to any one of claims 2-3, characterized in that, The first electronic device includes a protocol session management system and a transmission and reception system; Before sending the first data to the second electronic device via the WLAN connection and / or sending the first data to the second electronic device via the P2P connection, the method further includes: the protocol session management system determining the highest priority data path from the first data path list; The step of sending the first data to the second electronic device through the WLAN connection specifically includes: when the protocol session management system determines that the highest priority data path is the WLAN data path, it sends a first sending request to the sending and receiving system, the first sending request carrying the first data and information about the WLAN data path; in response to receiving the first sending request, the sending and receiving system sends the first data to the second electronic device through the WLAN data path; The step of sending the first data to the second electronic device through the P2P connection specifically includes: when the protocol session management system determines that the highest priority data path is the P2P data path, it sends a second sending request to the sending and receiving system, the second sending request carrying the first data and information about the P2P data path; in response to receiving the second sending request, the sending and receiving system sends the first data to the second electronic device through the P2P data path.

16. A device communication method, characterized in that, Applied to a second electronic device, the method includes: The second electronic device receives the first electronic device's initiative to establish a wireless local area network (WLAN) connection and a peer-to-peer (P2P) connection. The first electronic device and the second electronic device are respectively connected to the same wireless access point via WLAN. After the second electronic device successfully establishes a WLAN connection with the first electronic device, but before successfully establishing a P2P connection with the first electronic device, it receives first data sent by the first electronic device through the WLAN connection. After the second electronic device successfully establishes a P2P connection with the first electronic device, it receives the first data sent by the first electronic device through the P2P connection. The method further includes: When the second electronic device establishes a WLAN data path with the first electronic device, it receives a first message from the first electronic device. The first message carries the identifier of a first service session, a third port, and a first link type. The third port is the port of the WLAN IP of the first electronic device. If there is no service session corresponding to the first service session, a second service session is created, and the identifier of the second protocol session corresponding to the second service session is set to invalid. If the identifier of the protocol session corresponding to the second service session is invalid, a second protocol session is created, and the identifier of the second protocol session is updated to a valid value. A first port is requested on the WLAN IP of the first electronic device. A first response message is sent to the first electronic device. The first response message carries the identifier of the first service session, the identifier of the second service session, the first port, and the first link type. When the second electronic device establishes a P2P data path with the first electronic device, it receives a third message from the first electronic device. The third message carries the identifier of the first service session, a fourth port, and a second link type. The fourth port is the port of the second electronic device's P2P IP. The second electronic device checks whether it contains a second service session corresponding to the first service session. If it contains the second service session, it checks whether the identifier of the second protocol session is valid. If the identifier of the second protocol session is valid, it requests a second port on the second electronic device's P2P IP. The second electronic device then sends a third response message to the first electronic device. The third response message carries the identifier of the first service session, the identifier of the second service session, the second port, and the second link type.

17. The method according to claim 16, characterized in that, The method further includes: After the WLAN connection is successfully established, the second electronic device adds WLAN data path information to the second data path list. The WLAN data path information includes the WLAN IP and third port of the first electronic device. After the P2P connection is successfully established, the second electronic device adds P2P data path information to the second data path list. The P2P data path information includes the P2P IP and fourth port of the first electronic device.

18. The method according to claim 17, characterized in that, The P2P data path has a higher priority than the WLAN data path. The priority is used to determine the data path for sending the second data. The data path with the highest priority in the second data path list is used to send the second data, which is the service data of the second service session.

19. The method according to claim 17 or 18, characterized in that, The method further includes: When the P2P connection fails, the second electronic device deletes the information of the P2P data path from the second data path list and receives the first data from the first electronic device through the WLAN connection.

20. The method according to any one of claims 16-18, characterized in that, The method further includes: The second electronic device establishes a WLAN control path with the first electronic device; The second electronic device establishes a WLAN data path with the first electronic device through the WLAN control path.

21. The method according to claim 16, characterized in that, The method further includes: After creating the second service session, the second electronic device sets the available flag of the second service session to invalid.

22. The method according to claim 21, characterized in that, After the second electronic device adds WLAN data path information to the second data path list or adds P2P data path information to the second data path list, the method further includes: updating the available flag bit to a valid value when the available flag bit of the second service session is set to invalid.

23. The method according to any one of claims 16-18 and 21-22, characterized in that, The method further includes: The second electronic device establishes a P2P physical connection with the first electronic device; After the P2P physical connection is successfully established, the second electronic device establishes a P2P control path with the first electronic device; The second electronic device establishes a P2P data path with the first electronic device through the P2P control path.

24. The method according to claim 16, characterized in that, The second electronic device includes a data path establishment system and a business session management system; The method further includes: in response to the received first message, the data path establishment system sends a third session creation request to the business session management system, wherein the third session creation request carries the identifier of the first business session and is used to request the creation of a business session corresponding to the first business session; When the second electronic device does not contain a service session corresponding to the first service session, it creates a second service session, specifically including: in response to the received third session creation request, the service session management system creates a second service session when it does not contain a service session corresponding to the first service session, and sets the identifier of the second protocol session corresponding to the second service session to an invalid value; The method further includes: the business session management system sending a second message to the data path establishment system, the second message including the identifier of the second business session, the second message being used to indicate that the second business session has been created.

25. The method according to claim 22, characterized in that, The second electronic device includes a service session management system, a data path establishment system, and a protocol session management system; updating the available flag bit to a valid value specifically includes: The protocol session management system sends the identifier of the second protocol session to the business session management system through the data path establishment system; When the service session management system receives the identifier of the second service session, if the available flag of the second service session is invalid, it sends a second notification to the application. The second notification carries the identifier of the second service session and is used to indicate the transmission of second data, which is the service data of the second service session. After sending the second notification, the business session management system sets the available flag of the second business session to be valid.

26. The method according to claim 16, characterized in that, The second electronic device includes a data path establishment system, a protocol session management system, and a service session management system; The method further includes: the data path establishment system sending a fifth session creation request to the business session management system, the fifth session creation request carrying the identifier of the first business session, and the fifth session creation request being used to request the creation of the second business session; The second electronic device checks whether it contains a second business session corresponding to the first business session, specifically including: the business session management system responding to the fifth session creation request to check whether it contains a second business session corresponding to the first business session; The method further includes: when the business session management system includes the second business session, sending fourth information to the data path establishment system, the fourth information including the identifier of the second business session, the fourth information being used to indicate that the second business session has been created; When the second electronic device includes the second service session, it checks whether the identifier of the second protocol session is valid. Specifically, in response to receiving the fourth information, the data path establishment system checks whether the identifier of the second protocol session is valid. When the identifier of the second protocol session is valid, the second electronic device applies for the second port on the P2P IP of the second electronic device. Specifically, when the identifier of the first protocol session is valid, the data path establishment system sends a second port application instruction to the protocol session management system. The second port application instruction carries the P2P IP of the second electronic device. In response to the second port request instruction, the protocol session management system requests the second port on the P2P IP of the second electronic device.

27. The method according to any one of claims 16-18, 21-22, and 25-26, characterized in that, The second electronic device includes a transmitting and receiving system, a protocol session management system, a data path establishment system, and a service session management system; receiving the first data sent by the first electronic device through the WLAN connection specifically includes: When the sending and receiving system receives the first data, it sends the port for receiving the first data to the protocol session management system, and the port for receiving the first data is the first port. The protocol session management system determines the identifier of the second protocol session based on the first port, and sends the first data and the identifier of the second protocol session to the data path establishment system; The data path establishment system sends the first data and the identifier of the second business session corresponding to the second protocol session to the business session management system; The business session management system sends the first data and the identifier of the second business session to the application.

28. The method according to any one of claims 16-18, 21-22, and 25-26, characterized in that, The second electronic device includes a transmitting and receiving system, a protocol session management system, a data path establishment system, and a service session management system; receiving the first data sent by the first electronic device through the P2P connection specifically includes: When the sending and receiving system receives the first data, it sends the port for receiving the first data to the protocol session management system, and the port for receiving the first data is the second port. The protocol session management system determines the identifier of the second protocol session based on the second port, and sends the first data and the identifier of the second protocol session to the data path establishment system; The data path establishment system sends the first data and the identifier of the second business session corresponding to the second protocol session to the business session management system; The business session management system sends the first data and the identifier of the second business session to the application.

29. An electronic device, characterized in that, The device includes a memory and one or more processors; the memory is coupled to the one or more processors, the memory is used to store computer program code, the computer program code including computer instructions, and the one or more processors call the computer instructions to cause the electronic device to perform the method as described in any one of claims 1-15 or 16-28.

30. A computer-readable storage medium comprising instructions, characterized in that, When the instructions are executed on an electronic device, the electronic device causes the electronic device to perform the method as described in any one of claims 1-15 or 16-28.

Citation Information

Patent Citations

  • Method, device and system for transmitting data in near field

    CN114697934A

  • Data transmission method and electronic equipment

    CN117062252A