mqtt.py
646 Bytes
import paho.mqtt.client as mqtt
import random
import multiprocessing
import signal
import string
import sys
import logging
import time
import unittest
def mqtt_publish_flood(mqtt_server_IP, mqtt_server_PORT, topic):
client = mqtt.Client("AA")
client.connect(mqtt_server_IP, mqtt_server_PORT)
client.loop_start()
for _ in range(10000):
# 무작위 메세지 생성
message = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(50))
client.publish(topic, message, retain=True) # 발행
print(f"Sent message {message}")
client.loop_stop()
client.disconnect()