How to Set a P2P connection policy for anychat

Source: Internet
Author: User

Starting from anychat platform core SDK v2.8.6, anychat SDK has opened the kernel P2P connection policy to the upstream applications, allowing applications to intervene in kernel P2P connections, to meet the application requirements in various scenarios.

 

The typical code for setting a P2P connection policy is as follows:

 

  1. DWORD  dwP2PPolitic = 3; 2. BRAC_SetSDKOption(BRAC_SO_NETWORK_P2PPOLITIC,( const  char *)&dwP2PPolitic, sizeof ( DWORD ));

Currently, open P2P connection policies include the following values:

  • 0Prohibit P2P connectionDoes not actively establish P2P connections with other users or accept P2P connection requests initiated by other users;
  • 1Server Control P2P [Default], Automatically Establishes P2P with all users in the current room;
  • 2Upper-layer applications control P2P connectionsDoes not actively establish P2P connections with other users, but can accept P2P connection requests initiated by other users. However, applications can issue instructions for establishing P2P connections with specified users, after receiving the command from the upper-layer application, try to establish a P2P connection with the user;
  • 3Establish P2P connection as neededWhen you need to establish a P2P connection (such as requesting audio and video data from the other party), the system automatically tries to establish a P2P connection with the user and automatically accepts P2P connection requests from other users;

 

When a P2P connection is established successfully or is disconnected, the upper-layer application is notified through the P2P status change message.

 

The P2P connection resources of each client are limited (each client can establish a P2P connection with up to 30 users). Therefore, different P2P connection policies must be set for different application environments.

 

By default, the anychat SDK adopts the "server-controlled P2P" policy. After a user enters the room, he/she will establish a P2P relationship with all the users in the room, this mode is applicable to applications with no more than 50 users in the same room (considering that P2P connections to some clients may fail). If the number of users in the same room is large, we recommend that you use"Upper-layer applications control P2P connections"Or"Establish P2P connection as needed"Mode, so that the client can establish P2P with the desired user, without occupying P2P connection resources by irrelevant users.

 

The P2P connection policy can be dynamically adjusted after successful initialization, but onlyProhibit P2P connectionAfter the mode is set, the P2P connection with other users will be disconnected, and other modes will not be disconnected from the existing P2P connection. When the client is set to the "prohibit P2P connection" policy, all audio and video data (including transmitted to other users, other users) will be transferred through the server, applicable to some special applications.

 

Among all P2P connection policies, the optimal policy is"Establish P2P connection as needed", But it is not used as the default P2P connection policy of the SDK, mainly because this policy is newly added. to be compatible with the old version of the SDK,Server Control P2P"Policy is set as the default connection policy.

 

When set to"Upper-layer applications control P2P connectionsThen, you can actively establish a P2P connection with the specified user through the interface provided by the SDK. The typical code is as follows:

 

  1. DWORD  dwTargetUserId = 100; 2. BRAC_SetSDKOption(BRAC_SO_NETWORK_P2PCONNECT,( const  char *)&dwTargetUserId, sizeof ( DWORD ));

 

We recommend that you use the same P2P connection policy on an application platform. Otherwise, special situations may occur. For example, user a adopts the "Upper-layer application control P2P connection" policy, user B adopts the "server-controlled P2P" policy. After two users enter the room, although the upper-layer application does not send a request to user a to establish a P2P connection with user B, but in fact, both user a and user B will still establish P2P connections, because user B will actively establish connections with user.

 

Note: All the above "establishing P2P connections" does not mean that P2P connections can be established successfully. This is related to the actual network status, but indicates "trying to establish P2P connections with the other party ".

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.