#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include void handleServer(Block &commands); // handler for server mode void handleClient(Block &commands); // handler for client mode bool registerSignalHandler(void); // registers a Control-c handler void signalHandler(int signal); // The Control-C handler /// @brief /// @param argc /// @param argv [0] program. [1] SERVERMODE {port} [2] CLIENTMODE {serveripaddress} {serverport} SEND {FileName} /// @return -1:Error 1:Success int main(int argc, char **argv) { int returnCode(0); Profiler profiler; String version = "0.1.0.3"; // major version, minor version, patch, build std::cout << "sstp version " << version.str() << std::endl; if(!registerSignalHandler()) { std::cout << "Unable to register CTRL-C handler" << std::endl; return -1; } try { if(argc<2) { std::cout << "sstp SERVERMODE {port} | CLIENTMODE {serveripaddress} {serverport} {pathfileName}." << std::endl; std::cout << "SERVERMODE will listen on the specified port for a connection and receive the specified file." << std::endl; std::cout << "CLIENTMODE willl connect to the specified address and port and send the specfied file." << std::endl; return 1; } Block arguments; for(int index=0;index &commands) { Profiler profiler; if(commands.size()!=3) { std::cout << "Missing required parameters" << std::endl; return; } int port = commands[2].toInt(); std::cout << commands[1] << ":" << commands[2] << std::endl; SocketServer socketServer(commands[2].toInt()); socketServer.listen(); std::cout << "Done, total took " << Utility::formatNumber(profiler.end()) << "(ms)" << std::endl; } /// @brief [0]=program, [1]=CLIENTMODE, [2]=serveripaddress, [3]=serverport, [4]=pathfilename /// @param commands void handleClient(Block &commands) { Profiler profiler; if(commands.size()!=5) { std::cout << "Missing required parameters" << std::endl; return; } ClientSocketSender clientSocketSender(commands[2],commands[3].toInt()); bool returnCode = clientSocketSender.sendFile(commands[4]); if(!returnCode) { std::cout << "The transfer failed." << std::endl; } else { std::cout << "Transfer complete" << std::endl; } std::cout << "Done, total took " << Utility::formatNumber(profiler.end()) << "(ms)" << std::endl; }