exec.execute(new Runnable()
{
@Override
public void run()
{
SocketJoiner joiner = null;
try
{
while (!exec.isShutdown())
{
Socket proxy = new Socket(backend.getHost(), backend.getPort());
protocol.sendVersion(proxy);
protocol.sendMessage(proxy, protocol.proxyRequest(tunnelName, clientName));
String message = protocol.receiveMessage(proxy);
if (null != message && !"".equals(message))
{
Gson gson = new Gson();
Map result = gson.fromJson(message, Map.class);
if (null != result && null != result.get("proxy") && (Boolean) result.get("proxy"))
{
Socket local = new Socket("0.0.0.0", port);
joiner = new SocketJoiner(proxy, local);
joiner.join();
}
}
}
if (null != joiner)
{
joiner.stop();
}
}
catch (IOException e)
{
if (null != joiner)
{
joiner.stop();
}
}
}
});
}