public void identify() { long end, begin = System.currentTimeMillis(); end = begin; System.out.println( "Listening for multicast messages from nodes on the network for 1 second..."); while ((end - begin) < 1000) { try { byte buffer[] = new byte[mcsocket.getReceiveBufferSize()]; DatagramPacket packet = new DatagramPacket(buffer, buffer.length); mcsocket.receive(packet); nodes.put( XmlDecoder.XmlDecodeMulticastMessageId(new String(packet.getData())), XmlDecoder.XmlDecodeMulticastMessageAddress(new String(packet.getData()))); } catch (SocketTimeoutException e1) { System.out.println("No multicast messages received"); } catch (IOException e) { System.out.println("Problem identifying node in network"); e.printStackTrace(); } end = System.currentTimeMillis(); } assignId(); }
String dumpSocketInfo() throws Exception { StringBuffer sb = new StringBuffer(); sb.append("local_addr=").append(local_addr); sb.append(", mcast_addr=").append(mcast_addr); sb.append(", bind_addr=").append(bind_addr); sb.append(", ttl=").append(ip_ttl); if (sock != null) { sb.append("\nsocket: bound to "); sb.append(sock.getLocalAddress().getHostAddress()).append(":").append(sock.getLocalPort()); sb.append(", receive buffer size=").append(sock.getReceiveBufferSize()); sb.append(", send buffer size=").append(sock.getSendBufferSize()); } if (mcast_sock != null) { sb.append("\nmulticast socket: bound to "); sb.append(mcast_sock.getInterface().getHostAddress()) .append(":") .append(mcast_sock.getLocalPort()); sb.append(", send buffer size=").append(mcast_sock.getSendBufferSize()); sb.append(", receive buffer size=").append(mcast_sock.getReceiveBufferSize()); } return sb.toString(); }