Enhancements
This commit is contained in:
@@ -26,38 +26,55 @@ void handleClient(Block<String> &commands);
|
||||
/// @return
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int returnCode(0);
|
||||
Profiler profiler;
|
||||
String version = "1.00";
|
||||
|
||||
if(argc<2)
|
||||
std::cout << "sstp version " << version.str() << std::endl;
|
||||
try
|
||||
{
|
||||
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<String> arguments;
|
||||
for(int index=0;index<argc;index++)
|
||||
{
|
||||
String item(argv[index]);
|
||||
arguments.insert(item);
|
||||
}
|
||||
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<String> arguments;
|
||||
for(int index=0;index<argc;index++)
|
||||
{
|
||||
String item(argv[index]);
|
||||
arguments.insert(item);
|
||||
}
|
||||
|
||||
std::cout << argv[1] << std::endl;
|
||||
if(arguments[1]=="SERVERMODE")
|
||||
{
|
||||
handleServer(arguments);
|
||||
std::cout << argv[1] << std::endl;
|
||||
if(arguments[1]=="SERVERMODE")
|
||||
{
|
||||
handleServer(arguments);
|
||||
}
|
||||
else if(arguments[1]=="CLIENTMODE")
|
||||
{
|
||||
handleClient(arguments);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Unknown command " << arguments[1] << std::endl;
|
||||
returnCode=-1;
|
||||
}
|
||||
}
|
||||
else if(arguments[1]=="CLIENTMODE")
|
||||
catch(Exception& exception)
|
||||
{
|
||||
handleClient(arguments);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Unknown command " << arguments[1] << std::endl;
|
||||
std::cout << exception.toString() << std::endl;
|
||||
returnCode=-1;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
std::cout << "An unhandled exception was encountered" << std::endl;
|
||||
returnCode=-1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
std::cout << "Done, total took " << Utility::formatNumber(profiler.end()) << "(ms)" << std::endl;
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
/// @brief [0]=program [1]=SERVERMODE [2]={port}
|
||||
|
||||
@@ -105,13 +105,13 @@ bool SocketConnectionReceiver::handlePut(Block<String> &commands)
|
||||
{
|
||||
double elapsedTimeSeconds = profiler.elapsed()/1000.00;
|
||||
double bytesPerSecond = totalBytesRead / elapsedTimeSeconds;
|
||||
String strBytesPerSecond = Utility::bytesTransferredToString(bytesPerSecond);
|
||||
std::cout << "Transferred " << Utility::formatNumber(totalBytesRead) << " of " << Utility::formatNumber(fileLength) << " " << percent << " percent " << strBytesPerSecond << std::endl;
|
||||
String strBytesPerSecond = Utility::byteCountToString(bytesPerSecond);
|
||||
std::cout << "Transferred " << Utility::byteCountToString(totalBytesRead,false) << " of " << Utility::byteCountToString(fileLength,false) << " " << percent << " percent " << strBytesPerSecond << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
std::cout << "Transfer complete" << std::endl;
|
||||
std::cout << "Received " << Utility::formatNumber(totalBytesRead) << " in " << Utility::formatNumber(profiler.end()) << "(ms)" << std::endl;
|
||||
std::cout << "Received " << Utility::byteCountToString(totalBytesRead,false) << " in " << Utility::formatNumber(profiler.end()) << "(ms)" << std::endl;
|
||||
writeFile.close();
|
||||
return totalBytesRead==fileLength;
|
||||
}
|
||||
@@ -128,7 +128,7 @@ size_t SocketConnectionReceiver::expectPacket(void)
|
||||
sb.append("Received an invalid PCKT command");
|
||||
String str=sb.toString();
|
||||
std::cout << str << std::endl;
|
||||
throw new InvalidOperationException(str);
|
||||
throw InvalidOperationException(str);
|
||||
}
|
||||
if(!(subCommands[0]=="PCKT"))
|
||||
{
|
||||
@@ -138,7 +138,7 @@ size_t SocketConnectionReceiver::expectPacket(void)
|
||||
sb.append("Expected PCKT but received ").append(subCommands[0]);
|
||||
String str = sb.toString();
|
||||
std::cout << str << std::endl;
|
||||
throw new InvalidOperationException(str);
|
||||
throw InvalidOperationException(str);
|
||||
}
|
||||
size_t bufferLength = subCommands[1].toULong();
|
||||
return bufferLength;
|
||||
|
||||
Reference in New Issue
Block a user