Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 918
  • Last Modified:

socket connection through proxy

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
abhijitkhasnis
Asked:
abhijitkhasnis
1 Solution
 
fontaineCommented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now