0
votes

I am using Mina V2.1.3 for a network application; especially I have a udp session problem: I want to publish messages to specific "ips" and "ports" of some receivers via Udp. But I don't know (and I dont care) if such receivers are really listening to their ports and really received the packages.

In case that no receiver is listening to its port, Mina will receive an ICMP-Package back, which means, that the port is unreachable. Mina caughts this Package and throws an UnreachablePortException. Then Mina closes the session object and stops sending. My aim is to ignore the "destination unreachable" packages and therefore i want to still send udp packages ("fire-and-forget principle").

Here is my approach (some kind of pseudo code):

    NioDatagramConnector  connector = new NioDatagramConnector();
    ((DatagramSessionConfig) connector.getSessionConfig()).setCloseOnPortUnreachable(false);
    connector.getStatistics().setThroughputCalculationInterval(1);
    connector.getFilterChain().addLast("logger", new LoggingFilter());

    DefaultIoFilterChainBuilder filterChainBuilder = connector.getFilterChain();
    filterChainBuilder.addFilter(...);

    connector.setHandler(this);

    for (UDPClient client : udpClients) {
        ((NioDatagramConnector)connector).connect(new InetSocketAddress(client.getIP(), client.getPort()));
    }

    //Sending data
    while(true) {
        connector.broadcast("Message");
        Thread.sleep(10);
    }

    public void sessionClosed(IoSession session) throws Exception {
        System.out.println("Called after ICMP package is received");
    }

    //Further methods which are based of IoHandler

Based on debugging, I can see that Mina will remove this session and finally calls the closeSession()-method (given from IoHandler).

1

1 Answers

0
votes

As discussed in the bug report https://issues.apache.org/jira/browse/DIRMINA-1137

A UDP server socket needs to be open on the remote device at the remote port otherwise you will get UnreachablePortException. This exception is not done by MINA or JAVA but rather POSIX and is universal.