You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Rupinder Mazara <rs...@gmail.com> on 2007/09/25 22:22:21 UTC
setting up packet forwarding
hi all
I have a need help on the following problem
I have a server application that is sending out UDP packets on a
pre-determined port.
These are to be read and re-transmited on different port
I managed to do this using threads and good old datagram sockets part of
the code is below
How would this mechanism be achieved using MINA .
thanks
private void handlePackets() {
byte[] buffer = new byte[1024];
DatagramPacket readPacket = new DatagramPacket(buffer, buffer.length);
DatagramPacket sendPacket = new DatagramPacket(buffer, buffer.length);
///Message message = new Message();
try {
recieve.receive(readPacket);
sendPacket.setAddress(InetAddress.getByName( "localhost" ) ); //
machine ip
sendPacket.setPort( DESTINATION_PORT ); // machine port
sendPacket.setData(readPacket.getData()); // data to machine ...
recieve.send(sendPacket);
counter++;
System.out.println(">> forwarded "+counter);
} catch (IOException io) {
io.printStackTrace();
}
}
private boolean _flag_ = true;
public void run() {
while( _flag_ ){
handlePackets();
}
}
Re: setting up packet forwarding
Posted by Trustin Lee <tr...@gmail.com>.
Hi Rupinder,
You will need both DatagramAcceptor and DatagramConnector.
DatagramAcceptor can receive datagrams coming from any remote peer to
a certain bind address. Once you received data, you can use the
connector to send the message in your IoHandler implementation.
Because it's UDP, it should be very easy to implement.
Trustin
On 9/25/07, Rupinder Mazara <rs...@gmail.com> wrote:
> hi all
>
> I have a need help on the following problem
> I have a server application that is sending out UDP packets on a
> pre-determined port.
>
> These are to be read and re-transmited on different port
>
> I managed to do this using threads and good old datagram sockets part of
> the code is below
>
> How would this mechanism be achieved using MINA .
>
> thanks
>
>
> private void handlePackets() {
> byte[] buffer = new byte[1024];
> DatagramPacket readPacket = new DatagramPacket(buffer, buffer.length);
> DatagramPacket sendPacket = new DatagramPacket(buffer, buffer.length);
> ///Message message = new Message();
> try {
> recieve.receive(readPacket);
> sendPacket.setAddress(InetAddress.getByName( "localhost" ) ); //
> machine ip
> sendPacket.setPort( DESTINATION_PORT ); // machine port
> sendPacket.setData(readPacket.getData()); // data to machine ...
> recieve.send(sendPacket);
> counter++;
> System.out.println(">> forwarded "+counter);
> } catch (IOException io) {
> io.printStackTrace();
> }
> }
>
> private boolean _flag_ = true;
>
> public void run() {
> while( _flag_ ){
> handlePackets();
> }
> }
>
--
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6