Date: Fri, 10 Aug 2007 05:54:40 +0800 From: "dieter lin" <dieter.ccu@gmail.com> To: freebsd-java@freebsd.org Subject: JAVA IPV6 problem Message-ID: <84d790390708091454y6a13e762kef1e68c17955ae0b@mail.gmail.com>
next in thread | raw e-mail | index | archive | help
Hi all , I'm narrowing down a problem with java.net.SocketException on jdk-1.5.0.12p6,1 FreeBSD RELENG_6 . uname -a output FreeBSD dietertw.dyndns.org 6.2-STABLE FreeBSD 6.2-STABLE #4: Thu Aug 2 16:10:39 CST 2007 root@d dietertw.dyndns.org :/usr/obj/usr/src/sys/dieter: Here's the error: If I use the command "java -Djava.net.preferIPv4Stack=true Check",the result is right. Hoever, I use the command "setenv JAVA_OPS - Djava.net.preferIPv4Stack=true" to set environment . Then, I use "the command "java Check" . The error will occur like following : java.net.SocketException: Invalid argument at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333) at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java :195) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182) at java.net.Socket.connect(Socket.java:519) at java.net.Socket.connect(Socket.java:469) at sun.net.NetworkClient.doConnect(NetworkClient.java:157) at sun.net.www.http.HttpClient.openServer(HttpClient.java:382) at sun.net.www.http.HttpClient.openServer(HttpClient.java:509) at sun.net.www.http.HttpClient.<init>(HttpClient.java:231) at sun.net.www.http.HttpClient.New(HttpClient.java:304) at sun.net.www.http.HttpClient.New(HttpClient.java:316) at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient( HttpURLConnection.java:813) at sun.net.www.protocol.http.HttpURLConnection.plainConnect( HttpURLConnection.java:765) at sun.net.www.protocol.http.HttpURLConnection.connect( HttpURLConnection.java:690) at sun.net.www.protocol.http.HttpURLConnection.getInputStream( HttpURLConnection.java:934) at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java :367) at Check.exists(Check.java:20) at Check.main(Check.java:8) I'm able to reproduce the error with the following code, import java.net.*; import java.io.*; import java.net.*; public class Check { public static void main(String s[]) { System.out.println(exists("http://127.0.0.1/")); // System.out.println(exists("http://www.rgagnon.com/pagenotfound.html")); } static boolean exists(String URLName){ try { HttpURLConnection.setFollowRedirects(false); // note : you may also need // HttpURLConnection.setInstanceFollowRedirects(false) HttpURLConnection con = (HttpURLConnection) new URL(URLName).openConnection(); con.setRequestMethod("HEAD"); return (con.getResponseCode() == HttpURLConnection.HTTP_OK); } catch (Exception e) { e.printStackTrace(); return false; } } } Do Anyone meet the same error ?
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?84d790390708091454y6a13e762kef1e68c17955ae0b>