Anybody can give me a hint ?

I have 3 cases that I want to replace by MINA.

#1 - Send a UDP message using MulticastSocket and close the socket.
#2 - Send a UDP message using DatagramSocket but wait for a response (wait
until TTL)
#3 - Listen for UDP message using MulticastSocket (while(true))


2009/8/7 Survivant 00 <[email protected]>

> I have a little demo server that listen for multicast udp using
> multicastSocket.  I want to migrate to MINA, but I wasn't able to make it to
> run.
>
> I found some code on few forums.. but I never been able to receive anything
> with MINA.   If I run my MINA server.. messageReceived  if never called.
>
>
> I saw this post (https://issues.apache.org/jira/browse/DIRMINA-438) that
> looked what I need.. but there is a way with the latest release ?
>
> Here a snippet of my actual client/server that works well followed by my
> MINA server.
>
> my actual server demo
>
>
>         MulticastSocket mc_sock = new MulticastSocket(1900);
>
>         mc_sock.setReuseAddress(true);
>         mc_sock.joinGroup(InetAddress.getByName("239.255.255.250"));
> ..
>
> public void run() {
>         while (true) {
>             try {
>                 byte ssdvRecvBuf[] = new byte[1024];
>                 DatagramPacket dgmPacket2 = new DatagramPacket(ssdvRecvBuf,
> 1024);
>
>                 mc_sock.receive(dgmPacket2);
>
>                 int packetLen = dgmPacket2.getLength();
>                 String packetData = new String(dgmPacket2.getData(), 0,
> packetLen);
>
>                 System.out.println(packetData);
>             } catch (IOException e) {
>                 // TODO Auto-generated catch block
>                 e.printStackTrace();
>             }
>         }
>
>     }
>
>
> actual UDP CLIENT
>
> try {
>
>                 MulticastSocket mc_sock = new MulticastSocket(null);
>
>                 mc_sock.setReuseAddress(true);
>
>                 byte[] data = "CLIENT".getBytes();
>
>                 DatagramPacket packet = new DatagramPacket(data,
> data.length, InetAddress.getByName("239.255.255.250"), 1900);
>
>                 mc_sock.send(packet);
>
>                 mc_sock.close();
>
>             } catch (Throwable e) {
>             }
>
>
> here my mina server
>
>
> public class MinaSSDPServerDemo {
>
>     private static Logger logger =
> Logger.getLogger(MinaSSDPServerDemo.class.getName());
>
>     /**
>      * @param args
>      */
>     public static void main(String[] args) throws Exception {
>          int ipPort = 1900;
>
>          NioDatagramAcceptor acceptor = new NioDatagramAcceptor();
>          acceptor.setHandler(new IoHandlerAdapter() {
>
>              @Override
>             public void exceptionCaught(IoSession session, Throwable cause)
> throws Exception {
>                  logger.info("exceptionCaught");
>                 super.exceptionCaught(session, cause);
>             }
>
>             @Override
>             public void sessionClosed(IoSession session) throws Exception {
>                 logger.info("sessionClosed");
>                 super.sessionClosed(session);
>             }
>
>             @Override
>             public void sessionCreated(IoSession session) throws Exception
> {
>                 logger.info("sessionCreated");
>                 super.sessionCreated(session);
>             }
>
>             @Override
>             public void sessionIdle(IoSession session, IdleStatus status)
> throws Exception {
>                 logger.info("sessionIdle");
>                 super.sessionIdle(session, status);
>             }
>
>             public void messageReceived(IoSession session, Object obj)
> throws Exception {
>                  logger.info("received " + obj + " on " +
> session.getLocalAddress()); }
>              });
>
>          DatagramSessionConfig dcfg = acceptor.getSessionConfig();
>          dcfg.setReuseAddress(true);
>
>
>         // the magic ingredient - set *just the port*
>          logger.info("binding listener to wildcard address + port " +
> ipPort);
>          //acceptor.bind(InetAddress.getByName("239.255.255.250"), ipPort);
>
>          //acceptor.bind(new InetSocketAddress("239.255.255.250", ipPort));
>          acceptor.bind(new InetSocketAddress(ipPort));
>
>
>
>     }
>
> }
>

Reply via email to