-
Issues with java.net.Proxy class
When I run the following code I expect it to display:
194.36.10.154
aaa.bbb.ccc.ddd
where aaa.bbb.ccc.ddd is my real IP. This does not happen, it instead displays:
194.36.10.154
194.36.10.154
when I uncomment the pause, the code performs as expected. Is there something going on behind the scenes causing this or is it a bug in java?
Code:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.SocketAddress;
import java.net.URL;
import java.net.URLConnection;
public class ProxyTest {
public static void test1() {
String socks_server_proxy = "194.36.10.154";
int socks_port = 3128;
try {
SocketAddress addr = new InetSocketAddress(socks_server_proxy,
socks_port);
Proxy proxy = new Proxy(Proxy.Type.HTTP, addr);
URL url = new URL("http://312c.info/ip.php");
URLConnection conn = url.openConnection(proxy);
BufferedReader in = new BufferedReader(new InputStreamReader(conn
.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void test2() {
try {
URL url2 = new URL("http://312c.info/ip.php");
URLConnection conn2 = url2.openConnection(Proxy.NO_PROXY);
BufferedReader in2 = new BufferedReader(new InputStreamReader(conn2
.getInputStream()));
String line2;
while ((line2 = in2.readLine()) != null) {
System.out.println(line2);
}
in2.close();
} catch (Exception e) {
e.printStackTrace();
}
public static void p(Object[] s) {
for (int i = 0; i < s.length; i++)
if (s[i] != null)
System.out.println(s[i].toString());
else
System.out.println("null");
}
public static void main(String[] args)
{
test1();
// try {
// Thread.sleep(5000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
test2();
}
-
3 weeks, 300 views, and no comments?
-
-
Similar Threads
-
By deridder149 in forum Java
Replies: 1
Last Post: 08-29-2007, 08:22 AM
-
Replies: 3
Last Post: 04-26-2006, 04:20 AM
-
By none_none in forum Java
Replies: 17
Last Post: 04-28-2005, 03:00 PM
-
Replies: 1
Last Post: 11-09-2000, 05:38 PM
-
Replies: 1
Last Post: 09-06-2000, 01:13 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|