org.apache.mina.transport.nio

## Class NioUdpServer

- java.lang.Object
- - org.apache.mina.service.AbstractIoService
  - - org.apache.mina.service.server.AbstractIoServer
    - - org.apache.mina.transport.udp.AbstractUdpServer
      - - org.apache.mina.transport.nio.NioUdpServer

- All Implemented Interfaces:
    IoClient, IoServer, IoService, SelectorListener

      public class NioUdpServer
      extends AbstractUdpServer
      implements SelectorListener

  This class implements a UDP NIO based server.
  Author:
    Apache MINA Project

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.apache.mina.service.AbstractIoService

      `AbstractIoService.ServiceState`

  - ### Field Summary

    - ### Fields inherited from class org.apache.mina.service.AbstractIoService

      `config, ioHandlerExecutor`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `NioUdpServer()` Create an UDP server with a new selector pool of default size and a `IoHandlerExecutor` of default type ( `OrderedHandlerExecutor`)
    `NioUdpServer(SelectorLoop readSelectorLoop, IoHandlerExecutor handlerExecutor)` Create an UDP server with provided selector loops pool
    `NioUdpServer(UdpSessionConfig config)` Create an UDP server with a new selector pool of default size and a `IoHandlerExecutor` of default type ( `OrderedHandlerExecutor`)
    `NioUdpServer(UdpSessionConfig config, SelectorLoop readSelectorLoop, IoHandlerExecutor handlerExecutor)` Create an UDP server with provided selector loops pool

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `bind(int port)` Binds the server to the specified port.
    `void` | `bind(SocketAddress localAddress)` Binds to the specified local addresses and start to accept incoming connections.
    `IoFuture<IoSession>` | `connect(SocketAddress remoteAddress)` Connects to the specified remote address.
    `SocketAddress` | `getBoundAddress()` Returns the local addresses which are bound currently.
    `DatagramChannel` | `getDatagramChannel()` Get the inner datagram channel for read and write operations.
    `SelectionKey` | `getReadKey()`
    `void` | `ready(boolean accept, boolean connect, boolean read, ByteBuffer readBuffer, boolean write)`
    `void` | `setReadKey(SelectionKey readKey)`
    `void` | `unbind()` Unbinds from the local addresses that this service is bound to and stops to accept incoming connections.

    - ### Methods inherited from class org.apache.mina.transport.udp.AbstractUdpServer

      `getSessionConfig, initSecured, setSessionConfig`

    - ### Methods inherited from class org.apache.mina.service.server.AbstractIoServer

      `isReuseAddress, setReuseAddress, setSessionConfig`

    - ### Methods inherited from class org.apache.mina.service.AbstractIoService

      `fireServiceActivated, fireServiceInactivated, getFilters, getIoHandler, getIoHandlerExecutor, getManagedSessions, initState, isActive, isCreated, isDisposed, isDisposing, isSuspended, setActive, setCreated, setDisposed, setDisposing, setFilters, setIoHandler, setSuspended`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### NioUdpServer

          public NioUdpServer()

      Create an UDP server with a new selector pool of default size and a `IoHandlerExecutor` of default type ( `OrderedHandlerExecutor`)

    - #### NioUdpServer

          public NioUdpServer(UdpSessionConfig config)

      Create an UDP server with a new selector pool of default size and a `IoHandlerExecutor` of default type ( `OrderedHandlerExecutor`)
      Parameters:
        `sessionConfig` - The configuration to use for this server

    - #### NioUdpServer

          public NioUdpServer(SelectorLoop readSelectorLoop,
                      IoHandlerExecutor handlerExecutor)

      Create an UDP server with provided selector loops pool
      Parameters:
        `acceptSelectorLoop` - the selector loop for handling accept events (connection of new session)
        `readWriteSelectorLoop` - the pool of selector loop for handling read/write events of connected sessions
        `ioHandlerExecutor` - used for executing IoHandler event in another pool of thread (not in the low level I/O one). Use `null` if you don't want one. Be careful, the IoHandler processing will block the I/O operations.

    - #### NioUdpServer

          public NioUdpServer(UdpSessionConfig config,
                      SelectorLoop readSelectorLoop,
                      IoHandlerExecutor handlerExecutor)

      Create an UDP server with provided selector loops pool
      Parameters:
        `sessionConfig` - The configuration to use for this server
        `acceptSelectorLoop` - the selector loop for handling accept events (connection of new session)
        `ioHandlerExecutor` - used for executing IoHandler event in another pool of thread (not in the low level I/O one). Use `null` if you don't want one. Be careful, the IoHandler processing will block the I/O operations.

  - ### Method Detail

    - #### getDatagramChannel

          public DatagramChannel getDatagramChannel()

      Get the inner datagram channel for read and write operations. To be called by the `NioSelectorProcessor`
      Returns:
        the datagram channel bound to this `NioUdpServer`.

    - #### getBoundAddress

          public SocketAddress getBoundAddress()

      Returns the local addresses which are bound currently.
      Specified by:
        `getBoundAddress` in interface `IoServer`

    - #### bind

          public void bind(int port)

      Binds the server to the specified port.
      Specified by:
        `bind` in interface `IoServer`
      Parameters:
        `port` - the local TCP port to bind.

    - #### bind

          public void bind(SocketAddress localAddress)

      Binds to the specified local addresses and start to accept incoming connections.
      Specified by:
        `bind` in interface `IoServer`

    - #### connect

          public IoFuture<IoSession> connect(SocketAddress remoteAddress)

      Description copied from interface: `IoClient`
      Connects to the specified remote address.
      Specified by:
        `connect` in interface `IoClient`
      Parameters:
        `remoteAddress` - Remote `SocketAddress` to connect
      Returns:
        the `IoFuture` instance which is completed when the connection attempt initiated by this call succeeds or fails.

    - #### unbind

          public void unbind()

      Unbinds from the local addresses that this service is bound to and stops to accept incoming connections. This method returns silently if no local address is bound yet.
      Specified by:
        `unbind` in interface `IoServer`

    - #### getReadKey

          public SelectionKey getReadKey()

      Returns:
        the readKey

    - #### setReadKey

          public void setReadKey(SelectionKey readKey)

      Parameters:
        `readKey` - the readKey to set

    - #### ready

          public void ready(boolean accept,
                   boolean connect,
                   boolean read,
                   ByteBuffer readBuffer,
                   boolean write)

      Specified by:
        `ready` in interface `SelectorListener`

Copyright © 2009–2013 Apache MINA Project. All rights reserved.