Example usage for org.springframework.integration.ip.udp UnicastReceivingChannelAdapter setLocalAddress

List of usage examples for org.springframework.integration.ip.udp UnicastReceivingChannelAdapter setLocalAddress

Introduction

In this page you can find the example usage for org.springframework.integration.ip.udp UnicastReceivingChannelAdapter setLocalAddress.

Prototype

@Override
    public void setLocalAddress(String localAddress) 

Source Link

Usage

From source file:org.springframework.integration.ip.udp.UdpChannelAdapterTests.java

@SuppressWarnings("unchecked")
@Test/*from  ww  w  . j a  va  2  s.co m*/
@Ignore
public void testMulticastSender() throws Exception {
    QueueChannel channel = new QueueChannel(2);
    int port = SocketUtils.findAvailableUdpSocket();
    UnicastReceivingChannelAdapter adapter = new MulticastReceivingChannelAdapter("225.6.7.9", port);
    adapter.setOutputChannel(channel);
    String nic = SocketTestUtils.chooseANic(true);
    if (nic == null) { // no multicast support
        LogFactory.getLog(this.getClass()).error("No Multicast support");
        return;
    }
    adapter.setLocalAddress(nic);
    adapter.start();
    SocketTestUtils.waitListening(adapter);

    MulticastSendingMessageHandler handler = new MulticastSendingMessageHandler("225.6.7.9", port);
    handler.setLocalAddress(nic);
    Message<byte[]> message = MessageBuilder.withPayload("ABCD".getBytes()).build();
    handler.handleMessage(message);

    Message<byte[]> receivedMessage = (Message<byte[]>) channel.receive(2000);
    assertNotNull(receivedMessage);
    assertEquals(new String(message.getPayload()), new String(receivedMessage.getPayload()));
}