import std.algorithm : min;
import std.digest : toHexString;
listenTCP_s(1400, &proxyFun, "0.0.0.0");
void proxyFun(TCPConnection conn) @safe nothrow
TCPConnection client = connectTCP("www.smart-locator.com", 5050);
logInfo("Tracker open communication: %s", client.connected);
auto buffer = new ubyte[4096];
WaitForDataStatus conn_status = conn.waitForDataEx(150.msecs);
if (conn_status == WaitForDataStatus.dataAvailable)
size_t chunk = min(conn.leastSize, buffer.length);
conn.read(buffer, IOMode.once);
auto readData = buffer[0 .. chunk].dup;
logInfo("Tracker send data: %s", readData.toHexString);
else if (conn_status == WaitForDataStatus.noMoreData)
logInfo("Tracker closing connection");
WaitForDataStatus client_status = client.waitForDataEx(150.msecs);
if (client_status == WaitForDataStatus.dataAvailable)
size_t chunk = min(client.leastSize, buffer.length);
client.read(buffer, IOMode.once);
auto readData = buffer[0 .. chunk].dup;
logInfo("Platform send data: %s", readData.toHexString);
else if (client_status == WaitForDataStatus.noMoreData)
logInfo("Platform closing connection");
if ((conn_status | client_status) & WaitForDataStatus.noMoreData)
logInfo("Closing connection");
logInfo("Closed connection");
logInfo("Exception: %s", e.msg);