The best way to do raw socket programming involving Java

I have some existing C code. I use ICMP raw socket for Ping. I need to use this code in Java because Java does not support ICMP package When I wrap the code in JNI and call it, the C code cannot get the socket during execution:

Socket (af_inet, sock_raw, 1);

I guess Java has given up some privileges that prohibit Java processes from using raw sockets I must find a solution

I observed the following:

>If I write a C program and use runtime calls from Java, the forked code may open the socket. > If I run this native code from eclipse, it also works well I think this is because eclipse has started from eclipse Exe, not from Java Exe starts

This means that I can solve my problem by choosing one of these two strategies, but I don't like it either Is there any other way for Java to accept JNI code and open this socket?

Editor: the more I see this problem, I think it must be a Windows 7 related problem, how to start Java

It seems that if you get window behavior, or if you are on some other platform than windows, you can also use InetAddress Isreachable() method

Solution

Maybe use an existing Java Native socket library? Then you don't have to worry about coding JNI lib

See: http://www.savarese.com/software/rocksaw/

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>