Android JNI layer creates Linux socket error problem resolution

Source: Internet
Author: User

Problem:

You want to create a UDP socket on the JNI layer to communicate with the server, but there is no success. Finally found to be created socket failed (code for example below)

Create SOCKETG_SD = socket (af_inet, SOCK_DGRAM, 0), if ( -1 = = g_sd) {perror ("socket ()"); goto Err_socket;}
The workaround:

In the Androidmanifest.xml file. To join the access network:

<uses-permission android:name= "Android.permission.INTERNET"/>
(Join location for example below)

<?xml version= "1.0" encoding= "Utf-8"? ><manifest xmlns:android= "http://schemas.android.com/apk/res/        Android "package=" Com.aran.envmonitor "android:versioncode=" 1 "android:versionname=" 1.0 "> <uses-sdk android:minsdkversion= "android:targetsdkversion="/> <!--join network access and <uses-permissio n android:name= "Android.permission.INTERNET"/> <application android:allowbackup= "true" Android:ico n= "@drawable/ic_launcher" android:label= "@string/app_name" android:theme= "@style/apptheme" > <u Ses-library android:name= "Env_tools"/> <activity android:name= ". Mainactivity "android:label=" @string/app_name "> <intent-filter> <action Android:name= "Android.intent.action.MAIN"/> <category android:name= "Android.intent.category.LAUNCHER "/> </intent-filter> </activity> &LT;/application></manifest> 


Android JNI layer creates Linux socket error problem resolution

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.