bluerhinos / phpMQTT

a simple php class to connect/publish/subscribe to a MQTT broker
Other
765 stars 461 forks source link

stream_socket_client(): unable to connect (Connection refused) #105

Closed maddisondesigns closed 3 years ago

maddisondesigns commented 3 years ago

Hi,

I've seen a few issues here mentioning the above error, but it looks like they've all been closed for now.

I've just created a quick test file using your library. I'm trying to connect to an Amazon EC2 Instance (Ubuntu) that's running Mosquitto.

I've added inbound rules for TCP Port 1883 for both my local IP address, and the IP for an external web host. When I run my file from my own local server, it works perfectly, and I'm able to publish a message.

When I upload that same file to my web host, I get the following warnings, and the Publish fails

PHP Warning:  stream_socket_client(): unable to connect to tcp://xx.xx.xx.xx:1883 (Connection refused) in /.../phpMQTT.php on line 150
Error:stream_socket_create() 111, Connection refused
screenshot_467

If you have any suggestions on something I could try to get it working, it would be greatly appreciated. Thanks in advance:-)

maddisondesigns commented 3 years ago

I did some more testing with this. I uploaded my test file to another web host, and it worked perfectly, first time, which makes me believe that it's more than likely a server issue.

I've raised a support ticket with the hosts and they've said that they've whitelisted my EC2 Instance IP and Port 1883, but I'm still having the same issue. Just waiting for them to investigate further now.

maddisondesigns commented 3 years ago

This issue has been sorted. The hosting support guys said that they had to set some additional rules in the Firewall.

If anyone else has this issue, I would suggest contacting your hosting support to check that they're aren't blocking your outgoing messages.