mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rupinder Mazara" <rsmaz...@gmail.com>
Subject setting up packet forwarding
Date Tue, 25 Sep 2007 20:22:21 GMT
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();
      }
    }

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