|
Home > Archive > Apache Directory Project > February 2006 > [mina] Sending datagrams without connection
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
[mina] Sending datagrams without connection
|
|
| Dani Eichhorn 2006-02-23, 5:45 pm |
| I'm new to mina, so please excuse me, if this is a stupid question,
since the mail list archive seems to be broken...
In java.nio I have the choice if I want to send a datagram using a
connection, or if I'm using the DatagramChannel.recieve/send methods.
Do I have this choice in Mina as well, since it is built on top of
java.nio...
I'm working on a library for NAT traversal (UDP and TCP) for P2P
networks. For a NAT traversal technique called hole punching I need
to be able to send datagrams into the blue, without getting any
response in the first place. It works directly with java.nio, but I'd
like to use the convenience of mina...
Cheers
Dani
| |
| Trustin Lee 2006-02-25, 5:45 pm |
| Hi Dani,
On 2/24/06, Dani Eichhorn <dani.eichhorn-eR1wvSbX9og@public.gmane.org> wrote:
>
> I'm new to mina, so please excuse me, if this is a stupid question,
> since the mail list archive seems to be broken...
The link to the archive on our web site was broken. Now it's fixed.
In java.nio I have the choice if I want to send a datagram using a
> connection, or if I'm using the DatagramChannel.recieve/send methods.
> Do I have this choice in Mina as well, since it is built on top of
> java.nio...
For now, you have to bind first:
InetSocketAddress address = new InetSocketAddress( 8080 );
IoAcceptor acceptor = new DatagramAcceptor();
acceptor.bind( address, handler );
IoSession session = acceptor.newSession( address, new InetSocketAddress( "
remote.host.com", 8080 ) );
session.write( ... );
If you don't want to bind, there's no such way yet. Please let us know if
this becomes a problem. This means we need to modify our API to fill the
abstraction hole.
HTH,
Trustin
--
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP key fingerprints:
* E167 E6AF E73A CBCE EE41 4A29 544D DE48 FE95 4E7E
* B693 628E 6047 4F8F CFA4 455E 1C62 A7DC 0255 ECA6
| |
| Dani Eichhorn 2006-02-26, 5:45 pm |
| Hi Trustin
Thanks for your reply. Binding first is absolutely no problem. I
guess I just didn't think out-of-the-box enough to find the solution
you posted here by myself. I tried using a DatagramConnector instead,
but your way seems to be much more efficient:
/*
*** Sends more or less every 0.5 seconds a UDP message to
destination and listens to answers on the same port
**/
IoSession session;
IoConnector connector = new DatagramConnector();
ConnectFuture future = connector.connect(destination, new
InetSocketAddress (destination.getPort()), new UDPMinaTester( ));
future.join();
try {
session = future.getSession();
for(;;){
Thread.sleep(500);
session.write(this.message);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
I guess the whole "future" stuff is not necessary here, since there's
never really a connection it could wait for, is that right?
By the way: would the Mina team be interested in integrating NAT
traversal code into to library? In one way (from app developper view)
it's some kind of basic need, but to work it needs some kind of
complex infrastructure, like a not NATed rendezvous server...
Thanks for your great work with MINA! I tried to implement a clean
code for NAT traversal for several weeks, before I discovered your
framework. Starting again clean on top of Mina made it possible to
write good code within three days!
Cheers
Dani
Am 25.02.2006 um 10:32 schrieb Trustin Lee:
> Hi Dani,
>
> On 2/24/06, Dani Eichhorn <dani.eichhorn-eR1wvSbX9og@public.gmane.org> wrote:
> I'm new to mina, so please excuse me, if this is a stupid question,
> since the mail list archive seems to be broken...
>
> The link to the archive on our web site was broken. Now it's fixed.
>
> In java.nio I have the choice if I want to send a datagram using a
> connection, or if I'm using the DatagramChannel.recieve/send methods.
> Do I have this choice in Mina as well, since it is built on top of
> java.nio...
>
> For now, you have to bind first:
>
> InetSocketAddress address = new InetSocketAddress( 8080 );
> IoAcceptor acceptor = new DatagramAcceptor();
> acceptor.bind( address, handler );
> IoSession session = acceptor.newSession( address, new
> InetSocketAddress( "remote.host.com ", 8080 ) );
> session.write( ... );
>
> If you don't want to bind, there's no such way yet. Please let us
> know if this becomes a problem. This means we need to modify our
> API to fill the abstraction hole.
>
> HTH,
> Trustin
> --
> what we call human nature is actually human habit
> --
> http://gleamynode.net/
> --
> PGP key fingerprints:
> * E167 E6AF E73A CBCE EE41 4A29 544D DE48 FE95 4E7E
> * B693 628E 6047 4F8F CFA4 455E 1C62 A7DC 0255 ECA6
|
|
|
|
|