use of java.net.ServerSocket in project robovm by robovm.
the class ServerSocketChannelTest method test_read_Blocking_RealData.
/**
* @tests ServerSocketChannel#accept().socket()
*/
public void test_read_Blocking_RealData() throws IOException {
serverChannel.socket().bind(localAddr1);
ByteBuffer buf = ByteBuffer.allocate(CAPACITY_NORMAL);
for (int i = 0; i < CAPACITY_NORMAL; i++) {
buf.put((byte) i);
}
clientChannel.connect(localAddr1);
Socket serverSocket = serverChannel.accept().socket();
InputStream in = serverSocket.getInputStream();
buf.flip();
clientChannel.write(buf);
clientChannel.close();
assertReadResult(in, CAPACITY_NORMAL);
}
use of java.net.ServerSocket in project robovm by robovm.
the class ServerSocketChannelTest method test_read_NonBlocking_RealData.
/**
* @tests ServerSocketChannel#accept().socket()
*/
public void test_read_NonBlocking_RealData() throws Exception {
serverChannel.configureBlocking(false);
serverChannel.socket().bind(localAddr1);
ByteBuffer buf = ByteBuffer.allocate(CAPACITY_NORMAL);
for (int i = 0; i < CAPACITY_NORMAL; i++) {
buf.put((byte) i);
}
buf.flip();
clientChannel.connect(localAddr1);
Socket serverSocket = serverChannel.accept().socket();
InputStream in = serverSocket.getInputStream();
clientChannel.write(buf);
clientChannel.close();
assertReadResult(in, CAPACITY_NORMAL);
}
use of java.net.ServerSocket 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.net.ServerSocket 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.net.ServerSocket in project robovm by robovm.
the class ServerSocketChannelTest method testChannelBasicStatus.
public void testChannelBasicStatus() {
ServerSocket gotSocket = this.serverChannel.socket();
assertFalse(gotSocket.isClosed());
assertTrue(this.serverChannel.isBlocking());
assertFalse(this.serverChannel.isRegistered());
assertEquals(SelectionKey.OP_ACCEPT, this.serverChannel.validOps());
assertEquals(SelectorProvider.provider(), this.serverChannel.provider());
}
Aggregations