?
Solved

socket connection through proxy

Posted on 1998-10-14
1
Medium Priority
?
910 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
[X]
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
1 Comment
 
LVL 5

Accepted Solution

by:
fontaine earned 200 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

719 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