public final class DatagramChannelUtil
extends java.lang.Object
DatagramChannel
s.Modifier and Type | Method and Description |
---|---|
static java.nio.channels.DatagramChannel |
openChannelInet4()
Opens a new
DatagramChannel . |
public static java.nio.channels.DatagramChannel openChannelInet4() throws java.io.IOException
Opens a new DatagramChannel
. If possible, this method will call
DatagramChannel.open(ProtocolFamily)
, passing
StandardProtocolFamily.INET
. This will limit the socket to
IPv4.
Unfortunately, the DatagramChannel.open(ProtocolFamily)
method is only available in JDK 1.7 and newer. In order to stay
compatible with JDK 1.6 (both at compile-time and run-time), this method
actually uses reflection for calling the
DatagramChannel.open(ProtocolFamily)
method. If the method
cannot be called (for example because the software is running on JRE 1.6
or reflection fails due to security restrictions), it falls back to
calling DatagramChannel.open()
. In this case, however, the
returned channel will not be restricted to IPv4.
Any exception thrown by DatagramChannel.open()
or
DatagramChannel.open(ProtocolFamily)
is also thrown by this
method. Any exception caused by reflection is caught by this method and
DatagramChannel.open()
is called directly instead.
DatagramChannel.open()
or DatagramChannel.open(StandardProtocolFamily.INET)
(the latter is preferred).java.io.IOException
- if the called open
method throws such an
exception.Copyright © 2014–2017 aquenos GmbH. All rights reserved.