eclipse-paho / eclipse-paho/paho.mqtt.java

Proxy Problem with WebSockets

Open
#419 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
2.3k
Forks
919
PR merge metrics
No merged PRs in 30d

Description

- [x] Bug exists Release Version 1.2.0 ( Master Branch)
Hello everyone,

I want to use a proxy with websocket MQTT client but the programm does not take the http proxy into account and instead it tries to use a socks proxy. And even with a socks proxy i have the following error: java.net.SocketException: Malformed reply from SOCKS server : MqttException
Is this normal?

UPDATE:
We are able to use now an HTTP proxy by using a custom ConnectionFactory, but now we have an authentication problem even though i used an authenticator and the client is hanged!
This is the code:
```
class SocksSocketFactory extends SocketFactory {
public Socket createSocket() throws IOException{
final String username = "xxxxx";
final String password = "xxxxx";

Authenticator.setDefault(new Authenticator() {
protected java.net.PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password.toCharArray());
}
});
System.setProperty("http.proxyHost", "proxy.enterprise.com");
System.setProperty("http.proxyPort", "80");
System.setProperty("http.proxyUser", username);
System.setProperty("http.proxyPassword", password);

InetSocketAddress httpProxy = new InetSocketAddress("proxy.enterprise.com", 80);
Proxy proxy = new Proxy(Proxy.Type.HTTP, httpProxy);
Socket sock = new Socket(proxy);
return sock;
}
```
Here is the network flow:
![capture](https://user-images.githubusercontent.com/13731337/30743506-367f756c-9f9e-11e7-9f59-f401b83a9539.PNG)

Thank you in advance,
Amir

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.