catch (IOException e)
{
log.error(e);
}
VirtualServerSocket serverSocket = null;
try
{
serverSocket = new VirtualServerSocket();
assertTrue(serverSocket.isBound() == false);
assertTrue(serverSocket.isClosed() == false);
// Bind serverSocket to an unused local address. This will lead to the creation of a new
// real socket, bound to that address, and a MultiplexingManager to wrap it.
log.info("binding to: " + nextBindPort);
doBind(serverSocket, null, new InetSocketAddress(clientServerSocketHost, nextBindPort));
assertTrue(serverSocket.isBound() == true);
// Connect serverSocket to a remote address. This will cause the real socket to connect to a
// MasterServerSocket at that address, leading to the creation of a real socket on the
// remote host and a MultiplexingManager to wrap it.
log.info("connecting server socket to port: " + ++nextConnectPort);
InetSocketAddress address1 = new InetSocketAddress(basicBehaviorServerHost, nextConnectPort);
is = testSocket.getInputStream();
is.read();
serverSocket.connect(address1);
assertTrue(serverSocket.isConnected());
assertTrue(doOneServerSocketTest(serverSocket, nextBindPort));
serverSocket.close();
assertTrue(serverSocket.isBound() == true);
assertTrue(serverSocket.isClosed() == true);
}
catch (Exception e)
{
log.error(e);
e.printStackTrace();
fail();
}
try
{
// Create a new VirtualServerSocket, bind it to an unused local address, and connect it
// to the server. This will lead to the creation of a new real socket, wrapped by a MultiplexingManager,
// bound to that address and connected to the server.
nextBindPort++;
InetSocketAddress bindAddress = new InetSocketAddress(clientServerSocketHost, nextBindPort);
log.info("binding to: " + nextBindPort);
log.info("connecting server socket to port: " + ++nextConnectPort);
InetSocketAddress address2 = new InetSocketAddress(basicBehaviorServerHost, nextConnectPort);
is.read();
serverSocket = doBind(null, address2, bindAddress);
assertTrue(serverSocket.isBound() == true);
assertTrue(serverSocket.isConnected() == true);
assertTrue(serverSocket.isClosed() == false);
assertTrue(doOneServerSocketTest(serverSocket, nextBindPort));
serverSocket.close();
assertTrue(serverSocket.isBound() == true);
assertTrue(serverSocket.isConnected() == true);
assertTrue(serverSocket.isClosed() == true);
}
catch (Exception e)
{
log.error(e);
e.printStackTrace();