I'd like to establish a connection between my client and raspbian. Within my network, I can connect to my service at any time without any problems. Now I want to connect to my service via the internet. This is unfortunately not working when I try to use my internet ip for the connection.

client = new MqttClient("tcp://77.777.77.77:1883", "SendingdLoop");

My Java-Application tells me that the connection has been refused (so there is no timeout):

   Could not establish connection (32103) - java.net.ConnectException: Connection **refused**: connect          at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:75)
        at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:538)
        at java.lang.Thread.run(Thread.java:722)
    Caused by: java.net.ConnectException: Connection refused: connect
        at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
        at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:75)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
        at java.net.Socket.connect(Socket.java:579)
        at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:66)

I followed the official instructions to open the port: https://wiki.debian.org/iptables

my entry looks like this:

 -A INPUT -p tcp -m tcp --dport 1883 -j ACCEPT

When I check iptables,

iptables -L
 ACCEPT tcp -- anywhere anywhere  tcp dpt: 1883

I can see the rule is active.

Is there anything else I have to configure?

  • Is the IP correct? 77.777.77.77 – Laurent C. Mar 31 '14 at 12:28
  • thats just for the post...Like I said - the connection is refused, no timeout. – Goot Mar 31 '14 at 12:31

"Is there anything else I have to configure?"

Your router, perhaps. You really have not provided enough information to provide a definitive answer, all you've done is point out is not because of iptables...perhaps.

Iptables rules are processed in order. If that was the last rule appended (-A) and is last in the list when you look at iptables -L, then it can be superseded by a preceding rule. E.g., if the list looks like:

DROP everything
ACCEPT everything 

Nothing will be accepted because everthing will be dropped before the second rule is processed (more exactly, the second rule will never be processed because everything will find a match in the first rule).

| improve this answer | |
  • my router forwarded the connection from 1883 to 80 so your answer is correct. thanks... – Goot Mar 31 '14 at 13:05

I had the same problem with mqtt broker called vernemq, but solved it by adding the following.

  1. $ sudo vmq-admin listener show

    To show the list o allowed IP's and ports for vernemq

  2. $ sudo vmq-admin listener start port=1885 -a --mountpoint /appname --nr_of_acceptors=10 --max_connections=20000

    To add any IP and your new port. Now you should be able to connect without any problem.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.