Search in sources :

Example 76 with ServerSocket

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);
}
Also used : InputStream(java.io.InputStream) ByteBuffer(java.nio.ByteBuffer) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket)

Example 77 with ServerSocket

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);
}
Also used : InputStream(java.io.InputStream) ByteBuffer(java.nio.ByteBuffer) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket)

Example 78 with ServerSocket

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
    }
}
Also used : ServerSocket(java.net.ServerSocket) IllegalBlockingModeException(java.nio.channels.IllegalBlockingModeException)

Example 79 with ServerSocket

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
    }
}
Also used : ClosedChannelException(java.nio.channels.ClosedChannelException) ServerSocket(java.net.ServerSocket) IllegalBlockingModeException(java.nio.channels.IllegalBlockingModeException)

Example 80 with ServerSocket

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());
}
Also used : ServerSocket(java.net.ServerSocket)

Aggregations

ServerSocket (java.net.ServerSocket)736 IOException (java.io.IOException)336 Socket (java.net.Socket)265 InetSocketAddress (java.net.InetSocketAddress)131 Test (org.junit.Test)118 SocketException (java.net.SocketException)56 InputStream (java.io.InputStream)51 SocketTimeoutException (java.net.SocketTimeoutException)43 OutputStream (java.io.OutputStream)41 InetAddress (java.net.InetAddress)41 BindException (java.net.BindException)28 URL (java.net.URL)28 SSLServerSocket (javax.net.ssl.SSLServerSocket)26 InputStreamReader (java.io.InputStreamReader)24 UnknownHostException (java.net.UnknownHostException)24 File (java.io.File)23 BufferedReader (java.io.BufferedReader)21 SSLSocket (javax.net.ssl.SSLSocket)21 DatagramSocket (java.net.DatagramSocket)20 ServerSocketChannel (java.nio.channels.ServerSocketChannel)16