[英]In Android Native app failed to create a client socket. Error code:14 Unable to create socket: Permission denied
I have created an Android app calling a method in native code. 我创建了一个使用本机代码调用方法的Android应用。 I'm getting unable to create socket error.
我无法创建套接字错误。 Following code is compiled to libconnect.so.
以下代码编译为libconnect.so。 I have loaded this library in android app using (System.loadLibrary("connect").
我已经使用(System.loadLibrary(“ connect”)在Android应用程序中加载了此库。
#include<gio/gio.h>
#include<glib.h>
#include<android/log.h>
#include "connect.h"
int connect()
{
GSocketConnection *connection=NULL;
GSocketClient *client;
GSocketAddress *address;
GCancellable *cancellable=NULL;
GError *error=NULL;
address = g_network_address_new("192.168.0.1",8080);
if(address == NULL)
__android_log_print(6,"Connect Method","Address is not valid");
client = g_socket_client_new();
connection = g_socket_client_connect(client, (GSocketConnectable *)address, cancellable, &error);
__android_log_print(6,"Connect Method","Connecting... ");
if(connection == NULL)
__android_log_print(6,"Connect Method","Connection is null");
if(error != NULL)
__android_log_print(6,"Connect Method","Error code: %d , Error msg: %s",error->code,error->message);
return 0;
}
I'm getting the following logs: 我收到以下日志:
12-31 11:38:18.032: E/Connect Method(2330): Connecting...
12-31 11:38:18.032: E/Connect Method(2330): Connection is null
12-31 11:38:18.032: E/Connect Method(2330): Error code: 14 , Error msg: Unable to create socket: Permission denied
I have a server running in 192.168.0.1 at port 8080. I need the app to connect to the server and establish TCP connection. 我有一个服务器在端口8080的192.168.0.1中运行。我需要该应用程序才能连接到该服务器并建立TCP连接。 What does the error code 14 specify?
错误代码14指定什么? How to resolve this error?
如何解决这个错误?
should have added "android.permission.INTERNET" and "android.permission.ACCESS_NETWORK_STATE" android permissions in the AndroidManifest.xml. 应该在AndroidManifest.xml中添加了“ android.permission.INTERNET”和“ android.permission.ACCESS_NETWORK_STATE” android权限。
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.