I have created an Android app calling a method in native code. I'm getting unable to create socket error. Following code is compiled to libconnect.so. I have loaded this library in android app using (System.loadLibrary("connect").
#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. What does the error code 14 specify? How to resolve this error?
should have added "android.permission.INTERNET" and "android.permission.ACCESS_NETWORK_STATE" android permissions in the AndroidManifest.xml.
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With