use of java.nio.channels.IllegalBlockingModeException in project robovm by robovm.
the class ServerSocketChannelTest method test_socket_accept_Nonblocking_NotBound.
/**
* @tests ServerSocket#socket().accept()
*/
public void test_socket_accept_Nonblocking_NotBound() throws IOException {
// regression test for Harmony-748
ServerSocket gotSocket = serverChannel.socket();
serverChannel.configureBlocking(false);
try {
gotSocket.accept();
fail("Should throw an IllegalBlockingModeException");
} catch (IllegalBlockingModeException e) {
// expected
}
serverChannel.close();
try {
gotSocket.accept();
fail("Should throw an IllegalBlockingModeException");
} catch (IllegalBlockingModeException e) {
// expected
}
}
use of java.nio.channels.IllegalBlockingModeException in project robovm by robovm.
the class ServerSocketChannelTest method test_socket_accept_Nonblocking_Bound.
/**
* @tests ServerSocket#socket().accept()
*/
public void test_socket_accept_Nonblocking_Bound() throws IOException {
// regression test for Harmony-748
serverChannel.configureBlocking(false);
ServerSocket gotSocket = serverChannel.socket();
gotSocket.bind(localAddr1);
try {
gotSocket.accept();
fail("Should throw an IllegalBlockingModeException");
} catch (IllegalBlockingModeException e) {
// expected
}
serverChannel.close();
try {
gotSocket.accept();
fail("Should throw a ClosedChannelException");
} catch (ClosedChannelException e) {
// expected
}
}
use of java.nio.channels.IllegalBlockingModeException in project robovm by robovm.
the class IllegalBlockingModeExceptionTest method test_Constructor.
/**
* @tests {@link java.nio.channels.IllegalBlockingModeException#IllegalBlockingModeException()}
*/
public void test_Constructor() {
IllegalBlockingModeException e = new IllegalBlockingModeException();
assertNull(e.getMessage());
assertNull(e.getLocalizedMessage());
assertNull(e.getCause());
}
use of java.nio.channels.IllegalBlockingModeException in project SimpleServerClient by DeBukkIt.
the class Server method startListening.
/**
* Starts the listening thread waiting for messages from clients
*/
protected void startListening() {
if (listeningThread == null && server != null) {
listeningThread = new Thread(new Runnable() {
@Override
public void run() {
while (server != null) {
try {
onLog("[Server] Waiting for connection" + (secureMode ? " using SSL..." : "..."));
@SuppressWarnings("resource") final Socket // potential resource leak. tempSocket might not be closed.
tempSocket = server.accept();
ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(tempSocket.getInputStream()));
Object raw = ois.readObject();
if (raw instanceof Datapackage) {
final Datapackage msg = (Datapackage) raw;
onLog("[Server] Message received: " + msg);
// inspect all registered methods
for (final String current : idMethods.keySet()) {
// if the current method equals the identifier of the Datapackage...
if (msg.id().equalsIgnoreCase(current)) {
onLog("[Server] Executing method for identifier '" + msg.id() + "'");
// execute the Executable on a new thread
new Thread(new Runnable() {
@Override
public void run() {
// Run the method registered for the ID of this Datapackage
idMethods.get(current).run(msg, tempSocket);
// and close the temporary socket if it is no longer needed
if (!msg.id().equals(INTERNAL_LOGIN_ID)) {
try {
tempSocket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}).start();
break;
}
}
}
} catch (IllegalBlockingModeException | IOException | ClassNotFoundException e) {
e.printStackTrace();
}
}
}
});
listeningThread.start();
}
}
use of java.nio.channels.IllegalBlockingModeException in project j2objc by google.
the class DatagramChannelTest method test_socket_IllegalBlockingModeException.
/**
* @tests DatagramChannel#socket()
*/
public void test_socket_IllegalBlockingModeException() throws Exception {
// regression test for Harmony-1036
DatagramChannel channel = DatagramChannel.open();
channel.configureBlocking(false);
DatagramSocket socket = channel.socket();
try {
socket.send(null);
fail("should throw IllegalBlockingModeException");
} catch (IllegalBlockingModeException e) {
// expected
}
try {
socket.receive(null);
fail("should throw IllegalBlockingModeException");
} catch (IllegalBlockingModeException e) {
// expected
}
channel.close();
}
Aggregations