Note that there are some explanatory texts on larger screens.

plurals
  1. POdebugging C native function android ndk - sendto()
    primarykey
    data
    text
    <p>I've implemented a C native function with for android NDK, to send UDP packets. I have a working receiver but i seem to get nothing when i use the sender.</p> <ul> <li>How can i get more info from the return value of sendto? I'm having a hard time debugging native functions - no "debug step mode"</li> <li>can anyone see anything wrong about the sender code? is there something im not doing right?</li> </ul> <p>Thanks!</p> <pre><code>jstring Java_com_example_adhocktest_SenderUDP_SendUdpJNI( JNIEnv* env, jobject thiz, jstring ip, jstring message) { int PORT = 8888; int i; int sock_fd; char *_ip = (*env)-&gt;GetStringUTFChars(env, ip, 0); char *send_buf = (*env)-&gt;GetStringUTFChars(env, message, 0); //////////////// //////// create socket //////////////// if (( sock_fd = socket(AF_INET, SOCK_DGRAM, 0)) &lt; 0 ) { return (*env)-&gt;NewStringUTF(env,"Cannot create socket"); } struct sockaddr_in myaddr; //////////////// //////// send //////////////// struct sockaddr_in servaddr; memset((char*)&amp;servaddr, 0, sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_port = 8888; if ((inet_aton(_ip,&amp;servaddr.sin_addr)) == 0) { return (*env)-&gt;NewStringUTF(env,"Cannot decode IP address"); } int retval = sendto(sock_fd, send_buf, strlen(send_buf), 0, (struct sockaddr*)&amp;servaddr, sizeof(servaddr)); close(sock_fd); char str[100]; if ( retval &lt; 0) { sprintf(str, "sendto failed with %d", retval); } else { sprintf(str, "sendto success with %d", retval); } return (*env)-&gt;NewStringUTF(env,str); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload