I already have a broker running on my server and have subscribed few topics. If a new client wants to send his data to my server through my mqtt broker. Is there a possibility to obtain his ip address , publisher id ( and his new topic which he s gonna publish). Right now i am sending a sample program in which , if the publisher sends his data through the already subscribed topic then messages are received. If a new client connect to my broker with a new unsubscribed topic . how can i identify the topic name and publisher id, ip address. The subscriber program is as follows
package Testing;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Calendar;
import java.util.Date;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.eclipse.paho.client.mqttv3.MqttTopic;
public class ClientPublisher {
private static final String SERVER_URI = "tcp://localhost:1883";
private static final String
CLIENT_ID = "pub";
private MqttClient mqttClient;
public static String topic="hello";
public static void main(String args[]) throws Exception {
new ClientPublisher().doMqttTest(topic);
}
public void doMqttTest(String clienttopic) throws IOException {
try {
mqttClient = new MqttClient(SERVER_URI, CLIENT_ID);
mqttClient.connect();
} catch (MqttException e) {
e.printStackTrace();
}
while (true) {
//Date date = Calendar.getInstance().getTime();
String date="hey";
//System.out.println(date.toString());
try {
// Get an instance of the topic
MqttTopic topic = mqttClient.getTopic(clienttopic);
MqttMessage message = new MqttMessage(date.toString().getBytes());
MqttDeliveryToken token = topic.publish(message);
//System.out.println(topi);
// Wait until the message has been delivered to the server
token.waitForCompletion();
Thread.sleep(50 * 1000);
break;
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
Regards