use of java.net.PortUnreachableException in project netty by netty.
the class DatagramConnectNotExistsTest method testConnectNotExists.
public void testConnectNotExists(Bootstrap cb) {
// Currently not works on windows
// See https://github.com/netty/netty/issues/11285
assumeFalse(PlatformDependent.isWindows());
final Promise<Throwable> promise = ImmediateEventExecutor.INSTANCE.newPromise();
cb.handler(new ChannelInboundHandlerAdapter() {
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
promise.trySuccess(cause);
}
});
ChannelFuture future = cb.connect(NetUtil.LOCALHOST, SocketTestPermutation.BAD_PORT);
try {
Channel datagramChannel = future.syncUninterruptibly().channel();
assertTrue(datagramChannel.isActive());
datagramChannel.writeAndFlush(Unpooled.copiedBuffer("test", CharsetUtil.US_ASCII)).syncUninterruptibly();
if (!(datagramChannel instanceof OioDatagramChannel)) {
assertTrue(promise.syncUninterruptibly().getNow() instanceof PortUnreachableException);
}
} finally {
future.channel().close();
}
}
use of java.net.PortUnreachableException in project netty by netty.
the class EpollDatagramChannel method translateForConnected.
private IOException translateForConnected(NativeIoException e) {
// We need to correctly translate connect errors to match NIO behaviour.
if (e.expectedErr() == Errors.ERROR_ECONNREFUSED_NEGATIVE) {
PortUnreachableException error = new PortUnreachableException(e.getMessage());
error.initCause(e);
return error;
}
return e;
}
use of java.net.PortUnreachableException in project mc-dev by Bukkit.
the class RemoteStatusListener method run.
public void run() {
this.info("Query running on " + this.motd + ":" + this.bindPort);
this.clearedTime = MinecraftServer.ar();
this.p = new DatagramPacket(this.o, this.o.length);
try {
while (this.running) {
try {
this.socket.receive(this.p);
this.cleanChallenges();
this.parsePacket(this.p);
} catch (SocketTimeoutException sockettimeoutexception) {
this.cleanChallenges();
} catch (PortUnreachableException portunreachableexception) {
;
} catch (IOException ioexception) {
this.a(ioexception);
}
}
} finally {
this.e();
}
}
use of java.net.PortUnreachableException in project Aeron by real-logic.
the class UdpChannelTransport method receive.
/**
* Receive a datagram from the media layer.
*
* @param buffer into which the datagram will be received.
* @return the source address of the datagram if one is available otherwise false.
*/
public InetSocketAddress receive(final ByteBuffer buffer) {
buffer.clear();
InetSocketAddress address = null;
try {
if (receiveDatagramChannel.isOpen()) {
address = (InetSocketAddress) receiveDatagramChannel.receive(buffer);
}
} catch (final PortUnreachableException ignored) {
} catch (final Exception ex) {
LangUtil.rethrowUnchecked(ex);
}
return address;
}
use of java.net.PortUnreachableException in project helios by spotify.
the class DefaultProber method probeUdpPort.
private boolean probeUdpPort(String host, PortMapping portMapping) {
final Integer port = portMapping.getExternalPort();
try {
// Let's send a PING
// A UDP service should ignore any messages that do not conform to its protocol
// If it does then you probably should implement your own Prober or
// skip the probing by using a Dummy prober
final byte[] pingData = "PING".getBytes("UTF-8");
// Use ephemeral port number
final DatagramSocket serverSocket = new DatagramSocket(0);
final SocketAddress socketAddr = new InetSocketAddress(host, port);
serverSocket.connect(socketAddr);
final InetAddress address = InetAddress.getByName(host);
final DatagramPacket sendPacket = new DatagramPacket(pingData, pingData.length, address, port);
serverSocket.send(sendPacket);
// Wait for a response: This will cause either a timeout (OK) or a port not reachable (NOT OK)
final byte[] receiveData = new byte[8];
final DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
serverSocket.setSoTimeout(200);
serverSocket.receive(receivePacket);
} catch (SocketTimeoutException e) {
// OK we got a timeout. That means that the UDP port is up and listening
return true;
} catch (PortUnreachableException e) {
// there is no-one listening to the UDP port
return false;
} catch (SocketException e) {
LOG.warn(e.getMessage(), e);
return false;
} catch (IOException e) {
LOG.warn(e.getMessage(), e);
return false;
}
return false;
}
Aggregations