Search in sources :

Example 71 with ServerSocket

use of java.net.ServerSocket in project robovm by robovm.

the class SocketChannelTest method assertSocketAction_NonBlock_BeforeConnect.

private void assertSocketAction_NonBlock_BeforeConnect(Socket s) throws IOException {
    assertFalse(this.channel1.isConnected());
    this.server2 = new ServerSocket(localAddr2.getPort());
    try {
        s.connect(localAddr2);
        fail("Should throw IllegalBlockingModeException");
    } catch (IllegalBlockingModeException e1) {
    // OK.
    }
    if (this.channel1.isConnectionPending()) {
        try {
            s.bind(localAddr2);
            fail("Should throw ConnectionPendingException");
        } catch (ConnectionPendingException e1) {
        // OK.
        }
    } else {
        try {
            s.bind(localAddr2);
            fail("Should throw BindException");
        } catch (BindException e1) {
        // OK.
        }
    }
    assertFalse(this.channel1.isConnected());
    assertFalse(s.isConnected());
    s.close();
    assertTrue(s.isClosed());
    assertFalse(this.channel1.isOpen());
}
Also used : ConnectionPendingException(java.nio.channels.ConnectionPendingException) NoConnectionPendingException(java.nio.channels.NoConnectionPendingException) BindException(java.net.BindException) ServerSocket(java.net.ServerSocket) IllegalBlockingModeException(java.nio.channels.IllegalBlockingModeException)

Example 72 with ServerSocket

use of java.net.ServerSocket in project robovm by robovm.

the class SocketChannelTest method testCFII_EmptyHost.

public void testCFII_EmptyHost() throws Exception {
    statusNotConnected_NotPending();
    ServerSocket server = new ServerSocket(0);
    int port = server.getLocalPort();
    server.close();
    try {
        this.channel1.connect(new InetSocketAddress("", port));
        fail("Should throw ConnectException");
    } catch (ConnectException e) {
    // correct
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ServerSocket(java.net.ServerSocket) ConnectException(java.net.ConnectException)

Example 73 with ServerSocket

use of java.net.ServerSocket in project robovm by robovm.

the class ServerSocketChannelTest method testSocket_NonBlock_BeforeClose.

public void testSocket_NonBlock_BeforeClose() throws Exception {
    assertTrue(this.serverChannel.isOpen());
    this.serverChannel.configureBlocking(false);
    ServerSocket s1 = this.serverChannel.socket();
    assertFalse(s1.isClosed());
    assertSocketNotAccepted(s1);
    ServerSocket s2 = this.serverChannel.socket();
    // same
    assertSame(s1, s2);
    // socket close makes the channel close
    s1.close();
    assertFalse(this.serverChannel.isOpen());
}
Also used : ServerSocket(java.net.ServerSocket)

Example 74 with ServerSocket

use of java.net.ServerSocket in project robovm by robovm.

the class ServerSocketChannelTest method testSocket_Block_Closed.

public void testSocket_Block_Closed() throws Exception {
    this.serverChannel.close();
    assertFalse(this.serverChannel.isOpen());
    assertTrue(this.serverChannel.isBlocking());
    ServerSocket s1 = this.serverChannel.socket();
    assertTrue(s1.isClosed());
    assertSocketNotAccepted(s1);
    ServerSocket s2 = this.serverChannel.socket();
    // same
    assertSame(s1, s2);
}
Also used : ServerSocket(java.net.ServerSocket)

Example 75 with ServerSocket

use of java.net.ServerSocket in project robovm by robovm.

the class ServerSocketChannelTest method test_socket_accept_Blocking_Bound.

/**
     * @tests ServerSocket#socket().accept()
     */
public void test_socket_accept_Blocking_Bound() throws IOException {
    // regression test for Harmony-748
    serverChannel.configureBlocking(true);
    ServerSocket gotSocket = serverChannel.socket();
    gotSocket.bind(localAddr1);
    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)

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