To meet the laws and regulations of different countries or regions, the Agora RTC SDK supports geofencing. After enabling geofencing, the Agora SDK only connects to Agora servers within the specified region.
For example, if you specify North America as the region for connection, the SDK only connects to Agora servers in North America. When there is no available server in North American, the SDK throws an error instead of connecting to servers in another region.
As of v3.0.0.2, the Agora RTC Native SDK supports network geofencing.
When initializing the SDK by calling initialize
, set the areaCode
parameter in RtcEngineContext
to specify the region for connection.
AREA_CODE_GLOB
: (Default) GlobalAREA_CODE_CN
: Mainland ChinaAREA_CODE_NA
: North AmericaAREA_CODE_EU
: EuropeAREA_CODE_AS
: Asia, excluding Mainland ChinaAREA_CODE_JP
: JapanAREA_CODE_IN
: IndiaSpecify the region for connection as North America:
IRtcEngine *m_lpAgoraEngine = NULL;
RtcEngineContext ctx;
if(m_lpAgoraEngine == NULL)
m_lpAgoraEngine = createAgoraRtcEngine();
ctx.eventHandler = &m_EngineEventHandler;
ctx.appId = appId;
if (hWnd != NULL)
ctx.context = hWnd;
ctx.areaCode = rtc::AREA_CODE::AREA_CODE_NA;
m_lpAgoraEngine->initialize(ctx);
Exclude Mainland China from the regions for connection:
IRtcEngine *m_lpAgoraEngine = NULL;
RtcEngineContext ctx;
if(m_lpAgoraEngine == NULL)
m_lpAgoraEngine = createAgoraRtcEngine();
ctx.eventHandler = &m_EngineEventHandler;
ctx.appId = appId;
if (hWnd != NULL)
ctx.context = hWnd;
ctx.areaCode = rtc::AREA_CODE::AREA_CODE_GLOB ^ rtc::AREA_CODE::AREA_CODE_CN;
m_lpAgoraEngine->initialize(ctx);
Specify the regions for connection as North America, Europe, Asia, and India:
IRtcEngine *m_lpAgoraEngine = NULL;
RtcEngineContext ctx;
if(m_lpAgoraEngine == NULL)
m_lpAgoraEngine = createAgoraRtcEngine();
ctx.eventHandler = &m_EngineEventHandler;
ctx.appId = appId;
if (hWnd != NULL)
ctx.context = hWnd;
ctx.areaCode = rtc::AREA_CODE_NA | rtc::AREA_CODE_EU | rtc::AREA_CODE_AS | rtc::AREA_CODE_IN;
m_lpAgoraEngine->initialize(ctx);
If a firewall is deployed in your network environment, ensure that you whitelist all domains and ports listed in Use Cloud Proxy.