From e5fed94589cff4614b248cb3408397febc0b1be7 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 11 Jul 2022 07:20:34 -0700 Subject: Use same socket for sending --- src/main/java/org/traccar/broadcast/MulticastBroadcastService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/main/java/org/traccar/broadcast') diff --git a/src/main/java/org/traccar/broadcast/MulticastBroadcastService.java b/src/main/java/org/traccar/broadcast/MulticastBroadcastService.java index 877008eda..134bba797 100644 --- a/src/main/java/org/traccar/broadcast/MulticastBroadcastService.java +++ b/src/main/java/org/traccar/broadcast/MulticastBroadcastService.java @@ -150,12 +150,10 @@ public class MulticastBroadcastService implements BroadcastService { @Override public void start() throws IOException { service.submit(receiver); - publisherSocket = new DatagramSocket(); } @Override public void stop() { - publisherSocket.close(); service.shutdown(); } @@ -163,6 +161,7 @@ public class MulticastBroadcastService implements BroadcastService { @Override public void run() { try (MulticastSocket socket = new MulticastSocket(port)) { + publisherSocket = socket; socket.joinGroup(group, networkInterface); while (!service.isShutdown()) { DatagramPacket packet = new DatagramPacket(receiverBuffer, receiverBuffer.length); @@ -172,6 +171,7 @@ public class MulticastBroadcastService implements BroadcastService { handleMessage(objectMapper.readValue(data, BroadcastMessage.class)); } socket.leaveGroup(group, networkInterface); + publisherSocket = null; } catch (IOException e) { throw new RuntimeException(e); } -- cgit v1.2.3