Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

socket connection through proxy

Posted on 1998-10-14
1
884 Views
Last Modified: 2006-11-17
I am hooked on to the internet via a proxy server.I want to know how to open socket connection to a remote server (for eg java.sun.com) through a proxy server?
Note::
If i say Socket = new Socket("http://java.sun.com",80)
 I get an Exception "Route to host not found"
0
Comment
Question by:abhijitkhasnis
1 Comment
 
LVL 5

Accepted Solution

by:
fontaine earned 50 total points
ID: 1225789
The message you have is normal, because the first argument of the Socket constructor
has to be the host, i.e. java.sun.com, here. What you provided is the URL to the home
page of the java.sun.com Web site (served using the http protocol, the protocol used by
Web servers).

To connect through a proxy, you have to set the proxySet (...to true to inform the VM that you
want to connect through a proxy), proxyHost (to set to the proxy server host) and proxyPort
(to set to the proxy server port) properties. You have two options:

- Start the application using a command line in the following style :
   java -DproxySet=true -DproxyHost=myProxyServer.com -DproxyPort=80 MyJavaApp

- Use the Properties class:
   import java.util.properties;
   ...

  Properties systemSettings = System.getProperties();
  systemSettings.put("proxySet", true);
  systemSettings.put("proxyHost", "myProxyServer.com");
  systemSettings.put("proxyPort", "80");
  System.setProperties(systemSettings);
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question