/**
* Ensure shutting down the output stream of the socket causes an EOF
* on the other side.
*/
public void testShutdownOutput() throws Exception {
final RemoteServerSocket server = new RemoteServerSocket(client, 0);
final int serverPort = server.getLocalPort();
final Socket[] peer = new Socket[1];
try {
// Create another thread to connect to the socket.
final Socket[] peerClient = new Socket[1];
Thread thread = new Thread() {
public void run() {
try {
peerClient[0] = new Socket(
InetAddress.getLocalHost(), serverPort);
} catch (Throwable e) {
e.printStackTrace();
}
}
};
thread.start();
// Wait for the connection, then shut down the output stream.
Socket peerServer = server.accept();
try {
thread.join();
assertNotNull(peerClient[0]);
try {
assertFalse(peerServer.isOutputShutdown());
peerServer.shutdownOutput();
assertTrue(peerServer.isOutputShutdown());
try {
peerServer.getOutputStream().write(1);
fail("Expected IOException");
} catch (IOException e) {/* Expected */}
} finally {
peerClient[0].close();
}
} finally {
peerServer.close();
}
} finally {
server.close();
}
}