Package org.jboss.netty.channel.socket

Examples of org.jboss.netty.channel.socket.DatagramChannel


  @Override
  public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
      throws Exception
  {
    // Lookup the session from the local address.
    DatagramChannel datagramChannel = (DatagramChannel) e.getChannel();
    Session session = NettyUDPClient.CLIENTS.get(datagramChannel
        .getLocalAddress());
    if (null != session)
    {
      Event event = (Event) e.getMessage();
      // Pass the event on to the session
View Full Code Here


  @Override
  public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
      throws Exception
  {
    System.err.println(e.getCause());
    DatagramChannel datagramChannel = (DatagramChannel) e.getChannel();
    Session session = NettyUDPClient.CLIENTS.get(datagramChannel
        .getLocalAddress());
    if (null != session)
    {
      Event event = Events.event(e, Events.EXCEPTION);
      session.onEvent(event);
View Full Code Here

  @Override
  public void channelDisconnected(ChannelHandlerContext ctx,
      ChannelStateEvent e) throws Exception
  {
    DatagramChannel datagramChannel = (DatagramChannel) e.getChannel();
    Session session = NettyUDPClient.CLIENTS.get(datagramChannel
        .getLocalAddress());
    if ((null != session) && !session.isShuttingDown())
    {
      Event event = Events.event(e, Events.DISCONNECT);
      session.onEvent(event);
    }
    else if (null != session)
    {
      System.out.println("Session is already shutting down. "
          + "Disconnect event will be discarded for channel {}"
          + datagramChannel.getId());
    }

  }
View Full Code Here

  @Override
  public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e)
      throws Exception
  {
    DatagramChannel datagramChannel = (DatagramChannel) e.getChannel();
    Session session = NettyUDPClient.CLIENTS.get(datagramChannel
        .getLocalAddress());
    if ((null != session) && !session.isShuttingDown())
    {
      Event event = Events.event(e, Events.DISCONNECT);
      session.onEvent(event);
View Full Code Here

        // safe to send small packets in UDP.
        b.setOption(
                "receiveBufferSizePredictorFactory",
                new FixedReceiveBufferSizePredictorFactory(1024));

        DatagramChannel c = (DatagramChannel) b.bind(new InetSocketAddress(0));

        // Broadcast the QOTM request to port 8080.
        c.write("QOTM?", new InetSocketAddress("255.255.255.255", port));

        // QuoteOfTheMomentClientHandler will close the DatagramChannel when a
        // response is received.  If the channel is not closed within 5 seconds,
        // print an error message and quit.
        if (!c.getCloseFuture().awaitUninterruptibly(5000)) {
            System.err.println("QOTM request timed out.");
            c.close().awaitUninterruptibly();
        }

        f.releaseExternalResources();
    }
View Full Code Here

        // safe to send small packets in UDP.
        b.setOption(
                "receiveBufferSizePredictorFactory",
                new FixedReceiveBufferSizePredictorFactory(1024));

        DatagramChannel c = (DatagramChannel) b.bind(new InetSocketAddress(0));

        // Broadcast the QOTM request to port 8080.
        c.write("QOTM?", new InetSocketAddress("255.255.255.255", 8080));

        // QuoteOfTheMomentClientHandler will close the DatagramChannel when a
        // response is received.  If the channel is not closed within 5 seconds,
        // print an error message and quit.
        if (!c.getCloseFuture().awaitUninterruptibly(5000)) {
            System.err.println("QOTM request timed out.");
            c.close().awaitUninterruptibly();
        }

        f.releaseExternalResources();
    }
View Full Code Here

TOP

Related Classes of org.jboss.netty.channel.socket.DatagramChannel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.