@Override public boolean equals(Object other) { if (other instanceof BidibNetAddress) { BidibNetAddress bidibHost = (BidibNetAddress) other; if (bidibHost.getAddress().equals(address) && bidibHost.getPortNumber() == portNumber) { return true; } } return false; }
@Override public void send(NetBidibPort port, byte[] message) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("Send message to port: {}, message: {}", port, ByteUtils.bytesToHex(message)); } if (port != null) { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); // send the message to every known host for (BidibNetAddress host : knownBidibHosts) { bos.reset(); bos.write(message); LOGGER.info("Send message to address: {}, port: {}", host.getAddress(), host.getPortNumber()); // send the data to the host port.send(bos.toByteArray(), host.getAddress(), host.getPortNumber()); } } catch (IOException ex) { LOGGER.warn("Send message to port failed.", ex); throw new RuntimeException("Send message to datagram socket failed.", ex); } } else { LOGGER.warn("Send not possible, the port is closed."); } }
@Override public void send(NetBidibPort port, byte[] bytes) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("Send message to port: {}, message: {}", port, ByteUtils.bytesToHex(bytes)); } if (remoteAddress == null) { LOGGER.warn("### No remote addresses available. The message will not be sent!"); return; } if (port != null) { try { // add the bidib message payload sendBuffer.write(bytes); LOGGER.info("Send message to remote address, address: {}, port: {}", remoteAddress.getAddress(), remoteAddress.getPortNumber()); // send the message to the port port.send(sendBuffer.toByteArray(), remoteAddress.getAddress(), remoteAddress.getPortNumber()); } catch (IOException ex) { LOGGER.warn("Send message to port failed.", ex); throw new RuntimeException("Send message to datagram socket failed.", ex); } finally { sendBuffer.reset(); } } else { LOGGER.warn("Send not possible, the port is closed."); } }
@Test public void getPortNumber() { BidibNetAddress address1 = new BidibNetAddress(InetAddress.getLoopbackAddress(), 1234); Assert.assertEquals(address1.getPortNumber(), 1234); } }
addDelimiter(bos); LOGGER.info("Send message to address: {}, port: {}", host.getAddress(), host.getPortNumber()); port.send(bos.toByteArray(), host.getAddress(), host.getPortNumber());