Subscribe to local Broker in same Network

Hello,

I am trying to connect a Lego Robot as a subscriber to my local broker on my notebook. The client and the broker are in the same network.
I can connect to the online HiveMQ broker successfully. When I am trying to connect to my notebook it never works. I think I am doing something wrong in giving the IP adress of the notebook.

import com.hivemq.client.mqtt.mqtt5.Mqtt5BlockingClient;

import com.hivemq.client.mqtt.mqtt5.Mqtt5Client;

import java.io.IOException;
import java.net.InetAddress;

public class SubOnly{
static Mqtt5BlockingClient client;
static Mqtt5BlockingClient clientError;

public static void main(String... args) throws IOException {

    client =
    Mqtt5Client.builder()
        .identifier("Subscriber")
        .serverHost(InetAddress.getByName("192.168.0.9"))
        .serverPort(1883)
        .buildBlocking();
    client.connect();
    System.out.println("SubscribedBroker");

    System.out.println(InetAddress.getLocalHost().getHostAddress());
}}

Hi,
In Kotlin I can successfully connect with the client just using ip address, give it a try without the InetAddress.getByName.
val client: Mqtt3BlockingClient = Mqtt3Client.builder()
.identifier(“sensor01”)
.serverHost(“192.168.137.102”)
.serverPort(1883)
.buildBlocking()

1 Like

Hi,

It works now. The problem was the Windows Firewall. It was blocking the ports.

1 Like