From 844b827dc669eb6d75da8f52485fce22df66dff9 Mon Sep 17 00:00:00 2001 From: Edward Capriolo Date: Fri, 9 Jan 2015 12:27:55 -0500 Subject: [PATCH] Correcting gossipper so it only binds to a single host/port rather than all --- .../code/gossip/manager/PassiveGossipThread.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/google/code/gossip/manager/PassiveGossipThread.java b/src/main/java/com/google/code/gossip/manager/PassiveGossipThread.java index 40c33bf..477dd6f 100644 --- a/src/main/java/com/google/code/gossip/manager/PassiveGossipThread.java +++ b/src/main/java/com/google/code/gossip/manager/PassiveGossipThread.java @@ -3,6 +3,8 @@ package com.google.code.gossip.manager; import java.io.IOException; import java.net.DatagramPacket; import java.net.DatagramSocket; +import java.net.InetSocketAddress; +import java.net.SocketAddress; import java.net.SocketException; import java.util.ArrayList; import java.util.concurrent.atomic.AtomicBoolean; @@ -37,17 +39,22 @@ abstract public class PassiveGossipThread implements Runnable { // Start the service on the given port number. try { - _server = new DatagramSocket(_gossipManager.getMyself().getPort()); + //_server = new DatagramSocket( _gossipManager.getMyself().getPort()); + + SocketAddress socketAddress = new InetSocketAddress(_gossipManager.getMyself().getHost(), _gossipManager.getMyself().getPort()); + _server = new DatagramSocket(socketAddress); // The server successfully started on the current port. GossipService.info("Gossip service successfully initialized on port " + _gossipManager.getMyself().getPort()); GossipService.debug("I am " + _gossipManager.getMyself()); } catch (SocketException ex) { - // The port is probably already in use. + System.err.println(ex); _server = null; // Let's communicate this to the user. + /* GossipService.error("Error while starting the gossip service on port " + _gossipManager.getMyself().getPort() + ": " + ex.getMessage()); - System.exit(-1); + System.exit(-1);*/ + throw new RuntimeException(ex); } _keepRunning = new AtomicBoolean(true);