J
Jean-Paul
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.
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.