【发布时间】:2014-12-31 06:21:40
【问题描述】:
我创建了一个调用本机代码中的方法的 Android 应用。我无法创建套接字错误。以下代码编译为 libconnect.so。我已经使用 (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;
}
我收到以下日志:
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
我有一个服务器在 192.168.0.1 的 8080 端口上运行。我需要应用程序连接到服务器并建立 TCP 连接。错误代码 14 说明了什么?如何解决这个错误?
【问题讨论】:
标签: java android sockets java-native-interface native