#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // https://www.man7.org/linux/man-pages/man2/accept.2.html void handleServer(Block &commands); void handleClient(Block &commands); /// @brief /// @param argc /// @param argv [0] program. [1] SERVERMODE {port} [2] CLIENTMODE {serveripaddress} {serverport} SEND {FileName} /// @return int main(int argc, char **argv) { Profiler profiler; 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; }