DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    Jul 2009
    Posts
    6

    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();
    	}

  2. #2
    Join Date
    Jul 2009
    Posts
    6
    3 weeks, 300 views, and no comments?

  3. #3
    Join Date
    Jul 2009
    Posts
    6
    anyone?

  4. #4
    Join Date
    Jul 2009
    Posts
    6
    bump

Similar Threads

  1. Dynamic Loading.
    By deridder149 in forum Java
    Replies: 1
    Last Post: 08-29-2007, 08:22 AM
  2. Replies: 3
    Last Post: 04-26-2006, 04:20 AM
  3. Help with class/applet
    By none_none in forum Java
    Replies: 17
    Last Post: 04-28-2005, 03:00 PM
  4. Calling base class methods
    By GR in forum Java
    Replies: 1
    Last Post: 11-09-2000, 05:38 PM
  5. Abstract class
    By Manika in forum Java
    Replies: 1
    Last Post: 09-06-2000, 01:13 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links