Home > Mobile >  Use a localsocket as interprocess communication problems
Use a localsocket as interprocess communication problems

Time:03-31

Self-study Android the NDK development soon, use localsocket as interprocess communication mode
Wrote a Java server, at present to work properly,
Wrote a c jni interface of the client, packaged into release apk, can normal communication,
But the same code with the NDK build directly compiled into native app, just make a mistake, prompt localsocket connect error, do you have any good Suggestions?
Int localsocket_client_init (const char * server_name)
{
Int len.
Struct sockaddr_un remote;

Localsocket=socket (AF_UNIX SOCK_STREAM, 0).
If (localsocket==1)
{
MCINFO (" localsocket init error \ n ");
Return EXIT_FAILURE;
}

Remote. Sun_path [0]='\ 0';/* the abstract namespace */
Strcpy (remote. Sun_path + 1, server_name);
Remote. Sun_family=AF_UNIX;
Int nameLen=strlen (server_name);
Len=1 + + offsetof nameLen (struct sockaddr_un, sun_path);

If (connect (localsocket, (struct sockaddr *) & amp; Remote, len)==1)
{
MCINFO (" localsocket connect error \ n ");
Return EXIT_FAILURE;
}

Return EXIT_SUCCESS;
}
In under the NDK is written in c again a server, and before the c client can normal communication,

CodePudding user response:

The individual feels should be selinux permissions problems, due to the beginner, haven't find a solution,

CodePudding user response:

The connect (localsocket, (struct sockaddr *) & amp; Remote, len)
If need such sizeof (len)?

CodePudding user response:

Socket (AF_UNIX SOCK_STREAM, 0)
Such a socket (AF_INET, SOCK_STREAM, 0)?
  • Related