#include <base/Application.h>
#include <base/string/FormatInputStream.h>
#include <base/string/FormatOutputStream.h>
#include <base/Integer.h>
#include <base/net/StreamSocket.h>
#include <base/net/InetInterface.h>
#include <base/net/InetService.h>
#include <base/net/InetEndPoint.h>
#include <base/concurrency/Thread.h>
using namespace com::azure::dev::base;
private:
static const unsigned int MAJOR_VERSION = 1;
static const unsigned int MINOR_VERSION = 0;
public:
ClientApplication()
{
}
{
fout << "Server: " << host << ENDL;
{
fout << "Server addresses:" << ENDL;
unsigned int index = 0;
if (index == 0) {
address = temp;
fout << " address " << index++ << ": " << temp << " (USING THIS)" << ENDL;
} else {
fout << " address " << index++ << ": " << temp << ENDL;
}
}
}
fout <<
"End point: address=" << endPoint.
getAddress() <<
" port=" << endPoint.
getPort() << ENDL;
fout << "Initializing socket..." << ENDL;
fout << "Connecting socket..." << ENDL;
fout <<
"socket: remote address=" << socket.
getAddress() <<
" remote port=" << socket.
getPort() << ENDL;
fout << "Talking with server..." << ENDL;
{
fout << "Press enter to continue" << ENDL;
fout << "Sending request" << ENDL;
outstream << "Hi, I'm the client" << ENDL;
fout << "Waiting for response" << FLUSH;
while (!instream.
wait(1000000)) {
fout << '.' << FLUSH;
}
fout << ENDL;
fout << "Processing response" << ENDL;
fout << ">: ";
char ch;
instream >> ch;
fout << ch;
}
fout << "Sending termination request" << ENDL;
outstream << "Thank you and have a nice day" << ENDL;
}
fout << "Closing socket" << ENDL;
}
void main()
{
fout << getFormalName() << " version "
<< MAJOR_VERSION << '.' << MINOR_VERSION << EOL
<< "The Base Framework (Test Suite)" << EOL
<< ENDL;
case 0:
break;
case 1:
host = arguments[0];
break;
case 2:
host = arguments[0];
service = arguments[1];
break;
default:
fout << "client [host] [service]" << ENDL;
return;
}
client(host, service);
}
};
APPLICATION_STUB(ClientApplication);