Proxies with Sockets (multiple, non-http)

Discussion in 'Java' started by BobSmith, Aug 7, 2005.

  1. BobSmith

    BobSmith Guest

    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.
    BobSmith, Aug 7, 2005
    #1
    1. Advertising

  2. 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/
    Thomas Hawtin, Aug 8, 2005
    #2
    1. Advertising

  3. BobSmith

    BobSmith Guest

    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.
    BobSmith, Aug 8, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Smith

    Java HTTP proxies fail open?

    Chris Smith, Jul 18, 2005, in forum: Java
    Replies:
    1
    Views:
    492
    Acidus
    Jul 18, 2005
  2. Alan Kennedy
    Replies:
    0
    Views:
    351
    Alan Kennedy
    Jul 2, 2009
  3. Lennon Day-Reynolds

    SOAP4R+WSDL+HTTP proxies?

    Lennon Day-Reynolds, Aug 13, 2004, in forum: Ruby
    Replies:
    2
    Views:
    304
    Lennon Day-Reynolds
    Aug 14, 2004
  4. Zeke Koos
    Replies:
    0
    Views:
    195
    Zeke Koos
    Sep 15, 2003
  5. Olive

    Understanding http proxies

    Olive, Oct 13, 2012, in forum: Python
    Replies:
    3
    Views:
    202
    Olive
    Oct 15, 2012
Loading...

Share This Page