Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Proxies with Sockets (multiple, non-http)

Reply
Thread Tools

Proxies with Sockets (multiple, non-http)

 
 
BobSmith
Guest
Posts: n/a
 
      08-07-2005
How can I *sometimes* redirect a socket (created in a program I can not
change or extend) to go through a proxy server?

Changing the code that creates the socket is not possible, thus this
must be set up before the program is run (I run the program from within
my program, and in the same JVM).

Also, the key idea is to appear as if the requests are coming form
different computers, so different requests will need to be directed to
diferent proxy servers.

I was thinking replacing the SocketImplFactory using
Socket.setSocketImplFactory(new MySocketImplFactory);. I could send all
other requests for SocketImpl's back to the original SocketImplFactory
(thus not stuffing anything else up). My only remaining forseen problem
would be that I don't know how to make a SocketImpl, and I can't find
the original implementation of SocketImplFactory. (maybe its in com.sun
somewhere.... or in a inner class of Socket or ServerSocket or
something.....).

Any web searches on this topic return many sites about proxy servers
that have been writen in java, not about using proxy servers with java.
When I do find information about using a proxy in java, it is
invariably about using the system properties to set the http or ftp
proxies.

I haven't been thinking about this for very long, so there is probably
ALOT of things I haven't thought of.

----------

Any advise, instructions, help, ect... is greatly appreciated.
Non-constructive criticism will not be tolerated.

 
Reply With Quote
 
 
 
 
Thomas Hawtin
Guest
Posts: n/a
 
      08-07-2005
BobSmith wrote:
> How can I *sometimes* redirect a socket (created in a program I can not
> change or extend) to go through a proxy server?
>
> Changing the code that creates the socket is not possible, thus this
> must be set up before the program is run (I run the program from within
> my program, and in the same JVM).
>
> Also, the key idea is to appear as if the requests are coming form
> different computers, so different requests will need to be directed to
> diferent proxy servers.
>
> I was thinking replacing the SocketImplFactory using
> Socket.setSocketImplFactory(new MySocketImplFactory);. I could send all
> other requests for SocketImpl's back to the original SocketImplFactory
> (thus not stuffing anything else up). My only remaining forseen problem
> would be that I don't know how to make a SocketImpl, and I can't find
> the original implementation of SocketImplFactory. (maybe its in com.sun
> somewhere.... or in a inner class of Socket or ServerSocket or
> something.....).


It's null by default, AFAICS. When it's null java.net.PlainSocketImpl is
used (or SocksSocketImpl). As that is package private you'll need
reflection to get at it. You also need reflection to be able to reset
the SocketImplFactory.

I guess you could make a single connection out to a custom proxy (in
another process). Then after creating that setting your own
SocketImplFactory, the implementations of which multiplex onto your
single proxy connection.

Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
 
Reply With Quote
 
 
 
 
BobSmith
Guest
Posts: n/a
 
      08-08-2005
Yeah, that was the idea. Thanks for the info on the SocketImplFactory,
that will save me alot of time.

Its ironic that I spent all the time between writing that post and now,
with the exception of going to a movie, reading your
http://jroller.com/page/tackli ne/ site which I linked to from another
post in this group. I find you're entries very interesting, if a little
byond what I know.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Proxies, anyone? mad scientist Firefox 3 10-31-2004 05:22 AM
HttpURLConnection, Proxies and Authentication Roger Java 3 07-13-2004 01:53 PM
what loads proxies? =?Utf-8?B?bWtsYXBw?= ASP .Net 10 02-03-2004 06:55 PM
Calling com proxies from asp.net Ryan ASP .Net 0 12-11-2003 02:22 PM
Using AOP to implement dynamic proxies Michael N. Christoff Java 3 12-08-2003 05:12 PM



Advertisments