Android NDK socket connect() returning 0 when it should fail whilst on 3g
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have written a socket in the android NDK and a server in c. It is able to connect to the server fine. However if the server is down or I try to get it to connect to a different random IP the call to connect still returns 0 when it should return -1. Here is the code for the client: #include <stdio.h> #include <jni.h> #include <netdb.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <android/log.h> #include <unistd.h> #define APPNAME "MyApp" #define logcat(...) __android_log_print(ANDROID_LOG_VERBOSE, APPNAME