Solved

socket connection through proxy

Posted on 1998-10-14
1
888 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 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

739 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