New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] Unable to connect in proxy environment! #394
Comments
What version of the package are you using? Support for proxies (and the comment you referenced in the readme) was added in pull #322 which was committed on 21 Jun 2019. The latest release is 1.2.0 (19 Apr 2019) so if you are using that the proxy support is not included. If you are not using modules then you are probably using the latest code; but if you are using modules then you will be using 1.2.0 by default (run Having said that the full content of the paragraph from the documentation that you refer to is:
So this relates to MQTT over websockets (ws/wss) but as your code is attempting to connect via port 8883 (MQTT over TLS) I am assuming that you are using tcps (and not wss)? I don't think that its possible to proxy MQTT, other then MQTT over websockets, via an http/https proxy (they are different protocols). It may be possible via a SOCKS proxy but support for this would need to be added. |
Thanks MattBrittan for quick answer... I have recently started using the library (1 month back) so I assume I will have latest changes in place. Yes I am using 8883(or 1883) ports for the communication which required TCP based communication, earlier I was using java based solution there I need to implement custom socket for the same. But yes as you are saying the proxy support is only for the ws/wss then I can try the solution with wss and meanwhile can think on the custom socks proxy for the TCP. Just for curiosity, does any plan to support proxy for the TCP (8883 TLS security)? |
If you are using go modules then it will automatically get the highest version (meaning 1.2.0) but there have been quite a few changes since the last release (including the change I referenced earlier).
Its something that I think would be pretty simple to implement (golang.org/x/net/proxy includes support for SOCKS5) however I'm not aware of any plans to implement this (most changes are made by users who need the feature). |
Closing due to age/inactivity. Please feel free to reopen if this issue is occurring with the current release. |
Just an FYI, to clarify this somewhat potentially confusing issue to help out others in the same situation. It's possible to work with proxies better by supporting connection tunneling offered by HTTP/CONNECT for compatible proxies as defined in https://tools.ietf.org/html/rfc7231#section-4.3.6. This works by having the compliant proxy transparently relaying the data and the client issues the connect just writes the data to the proxy without needing to know much more. As a POC I attached a possible patch to make it work against mqtt.googleapis.com |
@amir-khassaia thanks for your comment; it may be useful for someone referring to this issue in the future. However if you wish to submit a patch then please make a pull request (I'd also suggest raising a new issue stating the problem you are attempting to solve). |
As per the documentation it says:
"If the client is running behind a corporate http/https proxy then the following environment variables HTTP_PROXY, HTTPS_PROXY and NO_PROXY are taken into account when establishing the connection."
But unfortunately same is not working for my usecase:
Application Logs:
Starting...
http_proxy: 198.134.0.10:4800
https_proxy: 198.134.0.10:4800
no_proxy: localhost,127.0.0.1
Inside connect block.
[client] Connect()
[store] memorystore initialized
[client] about to write new connect msg
[client] dial tcp 35.156.164.229:8883: i/o timeout
[client] Failed to connect to a broker
[store] memorystore closed
[Network Error : dial tcp 35.156.164.229:8883: i/o timeout]
I have tried to force fully set the proxy to "http://198.134.0.10:4800" instead of "198.134.0.10:4800", but it does not worked.
With non proxy environment its connecting with out any issue:
Application Logs:
Starting...
http_proxy: 198.134.0.10:4800
https_proxy: 198.134.0.10:4800
no_proxy: localhost,127.0.0.1
Inside connect block.
[client] Connect()
[store] memorystore initialized
[client] about to write new connect msg
[client] socket connected to broker
[client] Using MQTT 3.1.1 protocol
[net] connect started
[net] received connack
[client] client is connected
[client] exit startClient
Any suggestion or working example, what i am missing for the proxy environment?
Or do I need to create a custom socket for the proxy environment?
The text was updated successfully, but these errors were encountered: