mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fedechicco <fedechi...@gmail.com>
Subject Re: UDP bind problem
Date Mon, 07 May 2007 21:55:38 GMT
I surely do have the code:

this is the linearized code (without methods):

connector = new DatagramConnector();
acceptor = new DatagramAcceptor();

// Test for free ports
InetSocketAddress localaddr = new InetSocketAddress( startPort );
boolean flag = false;
        while( !flag ){
            flag = true;
            try {
                acceptor.bind( localaddr , handler );
                acceptor.unbind( localaddr );
            } catch (IOException ex) {
                flag = false;
                localaddr = new InetSocketAddress( localaddr.getPort() + 1
);
            }
        }

// connecting & waiting
ConnectFuture fut = connector.connect( remoteaddr , getLocalAddr(), handler
);
fut.join();

// writing client -> server handshake
IoSession outputIoSession = fut.getSession();
outputIoSession.write(buf);

// closing first IoSession
CloseFuture fut = outputIoSession.close();
fut.join();

//binding & check if the address is already free (it should with the
previous join)
boolean flag = false;
        while( !flag ){
            flag = true;
            try {
                acceptor.bind( localaddr , handler );
            } catch (IOException ex) {
                flag = false;
                try {
                    Thread.currentThread().sleep(50);
                } catch (InterruptedException ex2) {
                    ex2.printStackTrace();
                }
            }
        }


Then I tipically wait for the server to initiate the final IoSession with
the second message.

The problem is that the server sends the message during the time I'm not
bind yet and it receives an ICMP unreachable port message.
This is so, i can modify the code to allow connector & acceptor to share a
local port, giving to the connector session only the messages he wants, and
to the acceptor all the others, but please consider that usually my code
sucks. 8)
Which code should I modify?

Thx to everybody.

Fed

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message