catch (IOException e1)
{
log.error(e1);
}
SocketFactory socketFactory = VirtualSocketFactory.getDefault();
Socket socket = null;
try
{
socket = socketFactory.createSocket();
socket.connect(basicBehaviorServerSocketAddress);
assertTrue(doOneSocketFactoryTest(socket));
}
catch (Exception e)
{
log.error(e);
e.printStackTrace();
fail();
}
try
{
socket = socketFactory.createSocket(basicBehaviorServerHost, basicBehaviorServerPort);
assertTrue(doOneSocketFactoryTest(socket));
}
catch (Exception e)
{
log.error(e);
e.printStackTrace();
fail();
}
try
{
InetAddress inetAddress = InetAddress.getByName("localhost");
int localPort = random.nextInt() & 0xffff;
while (true)
{
try
{
socket = socketFactory.createSocket(basicBehaviorServerHost, basicBehaviorServerPort, inetAddress , localPort);
break;
}
catch (BindException e)
{
log.info("unable to bind to: " + localPort);
localPort = random.nextInt() & 0xffff;
}
catch (Exception e)
{
log.error(e);
e.printStackTrace();
fail();
}
}
assertTrue(socket.getLocalAddress().equals(inetAddress));
assertTrue(socket.getLocalPort() == localPort);
assertTrue(doOneSocketFactoryTest(socket));
}
catch (Exception e)
{
log.error(e);
e.printStackTrace();
fail();
}
try
{
InetAddress inetAddress = InetAddress.getByName(basicBehaviorServerHost);
socket = socketFactory.createSocket(inetAddress, basicBehaviorServerPort);
assertTrue(doOneSocketFactoryTest(socket));
}
catch (Exception e)
{
log.error(e);
e.printStackTrace();
fail();
}
try
{
while (true)
{
try
{
InetAddress remoteAddress = InetAddress.getByName(basicBehaviorServerHost);
InetAddress localAddress = InetAddress.getByName("localhost");
int localPort = random.nextInt() & 0xffff;
socket = socketFactory.createSocket(remoteAddress, basicBehaviorServerPort, localAddress , localPort);
assertTrue(socket.getLocalAddress().equals(localAddress));
assertTrue(socket.getLocalPort() == localPort);
assertTrue(doOneSocketFactoryTest(socket));
break;
}