socket through a firewall or proxy

How can I open a socket connection through a proxy or firewall?
Can I use the SocketImplementationFactory classes to write some settings for the socket? How?
octiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JodCommented:
In general if a firewall is blocking certain ports then it should stop you completely - that is what it is supposed to do. Implementing your own SocketImplementationFactory will not help if the Firewall is simply refusing connections on the port you wish to open.

The following links explain the problem.

http://forum.java.sun.com/forum?14@@.ee78a3c
http://forum.java.sun.com/forum?14@@.eea6da6
http://forum.java.sun.com/forum?14@@.ee780c4

However - there are ways around this using HTTP connections for example.

The details are all here:

http://developer.java.sun.com/developer/technicalArticles/InnerWorkings/Burrowing/index.html
0
octiAuthor Commented:
I like the method but it is artificial, even if solve the problem of client/server conection (I did not try it yet). I like to find out wat is with this SocketImplementationFactory calss and how can bee used. Thans anyway.
              Octi
0
mbormannCommented:
from
http://java.sun.com/people/linden/faq_d.html

10.(Sect. 15) How do I get a URLConnection to work through proxy firewalls? I.e. How do
    you get your application to do its web accesses through a proxy?

      This is typically needed for any net access to another domain. Tell the run time system
    what you are trying to do, by using these commandline arguments when you start the
    program.


    java -DproxySet=true -DproxyHost=SOMEHOST -DproxyPort=SOMENUM  classname

    Note proxyPort is optional and it defaults to 80. Without this, you will see an exception like
    java.net.UnknownHostException or java.net.NoRouteToHostException

    The proxy settings work for both java.net.URLConnection, and for java.net.Sockets.

    Netscape's and IE's JVMs (at least in versions 4.x+) take the proxy settings for applets from
    the browser's proxy configuration. You can also do URL proxies in applications (not
    applets) with the following code

     
        // set up to use proxy
        System.getProperties().put("proxySet", "true");
        System.getProperties().put("proxyHost", "myproxy.server.name");
        System.getProperties().put("proxyPort", "80");
         

    But how do I know the name of the proxy server?
    This code just tells you how you can get a URL connection to the outside. Since it is your
    proxy server, you are expected to know the name of it. There isn't any code that you can
    write that will allow arbitrary URL connections to be initiated from outside the firewall.
    Think about it! If there were, the firewall would not be doing its job.

    Also note there are corresponding socksProxyPort and socksProxyHost for when socks is
    used instead of proxy. The default socks port is 1080.


>>>>>SocketImplementationFactory

this 'class' is actually a SocketImplFactory and is a 'interface' used specifically by the JVM itself to set teh Factory for specifying how to use Sockets on that particular Operating System on that particular JVM.
You cant instantiate an interface,but some class which implements this interface is passed as a factory here and only the method createSocketImpl() is then visible /available to the factory.


see here is big class having many metjods

interface TT
{
void implement();
}

class Big implements TT
{
void method1()
{
//code
}
void method2()
{
//code
}
void implement()
{
//code
}
}

so when u say new Big() and pass it to some static method like they have done in Socket.java for factory ,recieve it as TT

say Other.processTT(new Big());
i.e

class Other
{
static void processTT(TT refr)
{
//code
//only refr.implement() is accessible here since u have chosen to throw //away all methods except implement() ,they are present but are invisible //to you right now.
}
}
The Factory is a well known Design Pattern and in this case is used to solve this dilemma.

A class can’t anticipate which kind of class of objects it must create.

Who provides the portability of Java ? the JVM does ,it specifies at runtime that use this Factory instance for this particular OS,this is different for different OS and JVM versions.

If u want to 'use' this 'class' then do some coding in JVM related stuff which is mostly in C/C++ with JNI.

hope it helps u.
see code in Socket.java

    public static synchronized void setSocketImplFactory(SocketImplFactory fac)
      throws IOException
    {
      if (factory != null) {
          throw new SocketException("factory already defined");
      }
      SecurityManager security = System.getSecurityManager();
      if (security != null) {
          security.checkSetFactory();
      }
      factory = fac;
    }
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

octiAuthor Commented:
I don't had the time to understand everything, what you did write here, but at least now I know what can I do with SocketImplementationFactory (or what I can't), if you are right...
        Octi

0
JodCommented:
You will eventually need to write some native code on the platform you are working on to actually make the sockets if you wish to follow this route. there is plenty of free exaples around in C on how to do this.

Firewall will still block on ports that connections are disallowed on, but mb is an expert in many details of Firewalls so I'm sure he can help you here on set up of firewalls.
0
octiAuthor Commented:
It is this little program on this link:
http://developer.java.sun.com/developer/technicalArticles/InnerWorkings/Burrowing/index.html
Did you tried? Because I tried and it does not work. I get a message like "Error connection/ server"
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.