Skip to content

Commit a13b025

Browse files
CristianDeluxevanous
authored andcommitted
Set SO_REUSEPORT on the Art-Net socket so a console on the same machine can share port 6454
On macOS and the BSDs a wildcard UDP port is shared only when every socket sets SO_REUSEPORT. QLC+ (Qt sets it) already bound to 6454 made BlenderDMX's bind fail with EADDRINUSE, so a console and the visualiser could not run on one machine. SO_REUSEADDR alone is not enough there; Linux keeps working as before, and the option is skipped where the platform lacks it.
1 parent 569040f commit a13b025

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

‎artnet.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
socket,
2828
)
2929

30+
try:
31+
from socket import SO_REUSEPORT
32+
except ImportError: # Windows
33+
SO_REUSEPORT = None
34+
3035
import bpy
3136

3237
from .data import DMX_Data
@@ -105,6 +110,12 @@ def __init__(self, ip_addr, *args, **kwargs):
105110
self._socket = socket(AF_INET, SOCK_DGRAM)
106111
self._socket.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
107112
self._socket.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
113+
if SO_REUSEPORT is not None:
114+
# On macOS and the BSDs a wildcard UDP port is shared only when
115+
# every socket sets SO_REUSEPORT; without it a console already
116+
# bound to 6454 on the same machine (QLC+, Qt sets it) makes
117+
# this bind fail with EADDRINUSE.
118+
self._socket.setsockopt(SOL_SOCKET, SO_REUSEPORT, 1)
108119
try:
109120
self._socket.bind((ip_addr, ARTNET_PORT))
110121
except OSError as e:

0 commit comments

Comments
 (0)