InputStream is_sync = syncSocket.getInputStream();
OutputStream os_sync = syncSocket.getOutputStream();
// Create a VirtualServerSocket and connect it to MasterServerSocket
// running on the server.
VirtualServerSocket serverSocket = new VirtualServerSocket(bindPort);
InetSocketAddress address1 = new InetSocketAddress(connectHost, connectPort + 1);
is_sync.read();
serverSocket.setSoTimeout(5000);
serverSocket.connect(address1);
// Call constructor to create a virtual socket and connect it to the port on the server
// to which the VirtualServerSocket is connected.
os_sync.write(5);
is_sync.read();
int port = serverSocket.getRemotePort();
Socket virtualSocket1 = new VirtualSocket(connectHost, port);
InputStream is1 = virtualSocket1.getInputStream();
OutputStream os1 = virtualSocket1.getOutputStream();
// Create a virtual socket by way of VirtualServerSocket.accept().
Socket virtualSocket2 = serverSocket.accept();
InputStream is2 = virtualSocket2.getInputStream();
OutputStream os2 = virtualSocket2.getOutputStream();
// Do some i/o and close sockets.
os1.write(9);
System.out.println(is1.read());
os2.write(11);
System.out.println(is2.read());
virtualSocket1.close();
virtualSocket2.close();
syncSocket.close();
serverSocket.close();
}
catch (Exception e)
{
e.printStackTrace();
}