Proxies with Sockets (multiple, non-http)

B

BobSmith

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.
 
T

Thomas Hawtin

BobSmith said:
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
 
B

BobSmith

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top