Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2006

Tip: Looking for answers? Try searching our database.

Problem with Proxy.Type.HTTP and Socket class

Thread view: 
Jean-Paul - 15 Feb 2006 18:44 GMT
Hi everyone,

I am currently writing a Jabber client for some specific purposes.
Basically the Jabber client, instead of being used as a chat client
will be sending some specific data encapsulated in the Jabber
protocols. Now, users might decide to use the client by connecting
directly or if in a corporate environment (university, office, and so
on) they might be forced to pass through a proxy. So I wrote my code in
such a way that depending on what is in the XML configuration file, a
direct connection is made or the connection is made through a Proxy
server, be it HTTP or SOCKS. So far, I have had no luck with SOCKS but
at least I do not get the same Exception that I get when I use
Proxy.Type.HTTP. Here's a sample code:

        // check whether the connection should occur through a proxy. If so,
get the settings and get
        // the proxy's connection
        InetSocketAddress proxyAddr = null;
        Proxy proxy = null;

        try {
            if(configurator.useProxy()) {
                proxyAddr = new InetSocketAddress(configurator.getProxyURI(),
Integer.parseInt(configurator.getProxyPort()));
                if(configurator.getProxyType().equals("SOCKS")) {
                    proxy = new Proxy(Proxy.Type.SOCKS, proxyAddr);
                } else if(configurator.getProxyType().equals("HTTP")) {
                    proxy = new Proxy(Proxy.Type.HTTP, proxyAddr);
                }
            }

            socket = new Socket(proxy);

            socket.connect(new InetSocketAddress(jabberHost, jabberHostPort));
        } catch(UnknownHostException e) {
            System.out.println("The following host " + jabberHost.toUpperCase()
+ " could not be found!");
            e.printStackTrace();
            return false;
        } catch(Exception e) {
            System.out.println("An IO error occured while trying to open a
socket to host " + jabberHost.toUpperCase() + " !");
            e.printStackTrace();
            return false;
        }

When in the configuration file, the proxy is set as HTTP, at the line
that says "socket = new Socket(proxy), I get a
java.lang.IllegalArgumentException: Invalid Proxy. Which obviously is
not true as I am connecting via that same proxy right now. And no, it
is not a proxy that requires a username and a password. So far, I could
not get any clue form my Internet search. Any help would be more than
welcome.

Thank you very much indeed.
Roedy Green - 17 Feb 2006 06:37 GMT
On 15 Feb 2006 10:44:27 -0800, "Jean-Paul"
<jeanpaul.hounkanrin@gmail.com> wrote, quoted or indirectly quoted
someone who said :

>I am currently writing a Jabber client for some specific purposes.
>Basically the Jabber client,

I looked into Jabber a few years ago and decided it would be a
nightmare for deployment since it used its own protocol and port
numbers.  That meant you would end up on the phone eternally solving
client firewall tunneling problems.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Jean-Paul - 17 Feb 2006 10:10 GMT
Possibly. But if you look at the code, a simple configuration to my XML
configuration file and I can actually connect to an HTTP server on port
80. However, this will still not happen if I cannot get the Proxy class
to work properly. This means that even if I forgot abou Jabber and
decided to do anything else, which I wont, I still won't get the code
to properly work. So, can I get a real answer to my problem?

Thanks.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.