private void sendBuffer(ByteArrayOutputStream sendData, InetAddress address, int portNumber) throws IOException { LOGGER.info("Send data to socket, address: {}, portNumber: {}, len: {}, sendData: {}", address, portNumber, sendData.size(), ByteUtils.bytesToHex(sendData)); try { DatagramPacket sendPacket = new DatagramPacket(sendData.toByteArray(), sendData.size(), address, portNumber); datagramSocket.send(sendPacket); // increment the sequence counter after sending the message sucessfully prepareNextSequence(); } finally { sendData.reset(); } }
/** * Send the data to the host. * * @param sendData * the data to send * @param address * the receiving address of the host * @param portNumber * the receiving port number of the host * @throws IOException */ public void send(byte[] sendData, InetAddress address, int portNumber) throws IOException { // if (LOGGER.isTraceEnabled()) { LOGGER.info("Send data to socket, port: {}, len: {}, bytes: {}", portNumber, sendData.length, ByteUtils.bytesToHex(sendData)); // } // send the data to the host // add the UDP packet wrapper ... sendDataBuffer.write(ByteUtils.getLowByte(currentSessionKey)); sendDataBuffer.write(ByteUtils.getHighByte(currentSessionKey)); sendDataBuffer.write(ByteUtils.getLowByte(sequence)); sendDataBuffer.write(ByteUtils.getHighByte(sequence)); sendDataBuffer.write(sendData); LOGGER.info("Send data to address: {}, portNumber: {}, sessionKey: {}, sequence: {}, sendData: {}", address, portNumber, currentSessionKey, sequence, ByteUtils.bytesToHex(sendDataBuffer)); // send the data to the host sendBuffer(sendDataBuffer, address, portNumber); }
LOGGER.info("Create UdpNetMessageHandler and NetBidibUdpPort!"); netMessageHandler = new UdpNetMessageHandler(messageReceiver, address, portNumber, connectionListener); netBidibPort = new NetBidibUdpPort(netMessageHandler);