建立与MQTT的多个连接时出错 - Python

时间:2017-09-13 16:04:27

标签: python mqtt

我试图在控制台中执行包含以下内容的python脚本:

python RC-accSimulation.py &
python RC-gyrSimulation.py &
python RT-accSimulation.py &
python RT-gyrSimulation.py &
python LC-accSimulation.py &
python LC-gyrSimulation.py &
python LT-accSimulation.py &
python LT-gyrSimulation.py &

这些.py文件完全相同(以下为例):

import paho.mqtt.client as mqtt

raspberry_MQTT_ip = '192.168.1.201'

jsonData = "..."

#Sending to MQTT Server the jsonData
mqttClient = mqtt.Client()
mqttClient.connect(host=raspberry_MQTT_ip, port=1883)
mqttClient.publish("topic/sensorRTgyr",jsonData)

如果我在脚本中执行五个或更少的.py文件,一切正常。 不幸的是,如果我尝试执行脚本中出现的每个文件,则会引发以下错误:

Traceback (most recent call last):   File "/Users/giordano/Dropbox/Andrea/tesi/sensorsScripts/simulatedsensors/RT-gyrSimulation.py", line 60, in <module>
    mqttClient = mqtt.Client()   File "/Library/Python/2.7/site-packages/paho/mqtt/client.py", line 497, in
__init__
    self._sockpairR, self._sockpairW = _socketpair_compat()   File "/Library/Python/2.7/site-packages/paho/mqtt/client.py", line 245, in
_socketpair_compat
    sock1.connect(("127.0.0.1", port))   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 228, in meth
    return getattr(self._sock,name)(*args) socket.error: [Errno 49] Can't assign requested address

复制脚本中存在的每个py文件。 我很困惑,因为只要同时执行5个py文件的更多信息就会显示错误。我尝试了不同的组合以找到特定的错误文件,但没有人有罪。

0 个答案:

没有答案