wood burning stoves 2.0*
The moose likes Sockets and Internet Protocols and the fly likes Socket connection from behind the Proxy Server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Socket connection from behind the Proxy Server" Watch "Socket connection from behind the Proxy Server" New topic
Author

Socket connection from behind the Proxy Server

Reeti Saha
Ranch Hand

Joined: Jun 26, 2001
Posts: 34
Hello Everyone
I've one application which opens a socket to connect and retrieve data from internet. Now my machine has gone behind a proxy server and I'm not able to connect to internet from my same old aplication. Can anyone pls. help me as how to solve this problem.. How can I provide the username and password to connect to the net. An example code will be highly appreciated.
It's urgent.
Regards
Reeti
Banana Tower
Greenhorn

Joined: Nov 22, 2001
Posts: 5
Try this( change proxyPort and proxyHost )
import sun.misc.BASE64Encoder;
System.getProperties().put("proxySet","true");
System.getProperties().put("proxyHost",proxyHost);
System.getProperties().put("proxyPort",proxyPort);
String proxyAuthentication = "username assword";
String encodedPassword = "Basic " + new BASE64Encoder().encode(proxyAuthentication.getBytes());
URL url = new URL(someurl);
URLConnection conn = url.openConnection();
conn.setRequestProperty("Proxy-Authorization",encodedPassword);
I am new to Java but this works for java 1.3.0_02
Check out Javaworld.com tip #42
cheers,
brian
Banana Tower
Greenhorn

Joined: Nov 22, 2001
Posts: 5
Sorry about the smily face....
That should read "username:password"
:P
Reeti Saha
Ranch Hand

Joined: Jun 26, 2001
Posts: 34
Thanks for the reply, but I've already tried this, somehow this is not working. I don't want to make an URLConnection instead I want to open a socket connection.
Would u pls. try to help me.
Regards
Reeti
Anirban Chatterjee
Greenhorn

Joined: Feb 06, 2001
Posts: 18
try out :
System.getProperties().setProperty("socksProxySet", "true");
System.getProperties().setProperty("socksProxyHost", proxyServerName);
System.getProperties().setProperty("socksProxyPort", proxyServerPort);
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Socket connection from behind the Proxy Server
 
Similar Threads
Working with Internet URL through Proxy from Java Code
Generated Stub and Proxy Settings !!
Working with Internet URL from Eclipse
java.net
HttpConnection through proxy