Question:
I try to open a socket connection on a Linux machine through JNI. If I combine Java_Socket_socket and Java_Socket_bind in same C function, the JNI call works perfectly, but it doesn’t work when I run methods sequentially.This is my code
gcc ... && a.out
-> then no error occurs. What can be reason?Can it be because file descriptor is closed?
Answer:
The issue is that you’re treatingAF_UNIX
socket as AF_INET
one. You can’t use sockaddr_in
for AF_UNIX
socket and also you can’t bind it to an IP address.I think that you’ve made a typo in your socket definition code. Instead of
If you have better answer, please add a comment about this, thank you!