#include <base/Application.h>
#include <base/string/FormatInputStream.h>
#include <base/string/FormatOutputStream.h>
#include <base/net/InetInterface.h>
#include <base/net/InetService.h>
#include <base/net/ServerSocket.h>
#include <base/Integer.h>
#include <base/TypeInfo.h>
using namespace com::azure::dev::base;
private:
static const unsigned int MAJOR_VERSION = 1;
static const unsigned int MINOR_VERSION = 0;
public:
ServerApplication()
{
}
{
fout << "Available interfaces:" << ENDL;
fout <<
" interface: index=" << i.
getIndex() <<
" name=" << i.
getName() << ENDL;
}
}
if (a == "") {
fout << "Local addresses:" << ENDL;
unsigned int index = 0;
if (index == 0) {
address = temp;
fout << " address " << index++ << ": " << temp << " (USING THIS)" << ENDL;
} else {
fout << " address " << index++ << ": " << temp << ENDL;
}
}
} else {
}
unsigned short port = 0;
try {
if ((integer < 0) || (integer > 0xffff)) {
}
port = integer;
try {
fout <<
"Service: name=" << service.
getName()
return;
}
}
fout << "Initializing server socket..." << ENDL;
fout << "Server address..." << ENDL;
fout << "Waiting for client to connect..." << ENDL;
unsigned int connection = 1;
bool terminate = false;
while (!terminate) {
fout << "Listening for connections..." << ENDL;
fout << "Connection number " << connection++ << " established from" << ENDL;
fout <<
" remote: address=" << socket.
getAddress() <<
" port=" << socket.
getPort() << ENDL;
fout << "Talking with client..." << ENDL;
{
fout << "Waiting for request" << FLUSH;
while (!instream.
wait(1000000)) {
fout << '.' << FLUSH;
}
fout << ENDL;
fout << "Processing request" << ENDL;
fout << ">: ";
char ch;
instream >> ch;
fout << ch;
}
fout << "Sending acknowledge" << ENDL;
outstream << "Hi, I'm the server and this is my response" << ENDL;
fout << "Waiting for termination request" << FLUSH;
while (!instream.
wait(1000000)) {
fout << '.' << FLUSH;
}
fout << ENDL;
fout << "Processing terminating request" << ENDL;
fout << ">: ";
char ch;
instream >> ch;
fout << ch;
}
}
fout << "Closing connection..." << ENDL;
if (connection == 5) {
terminate = true;
}
}
fout << "Closing server socket..." << ENDL;
}
void main()
{
fout << getFormalName() << " version "
<< MAJOR_VERSION << '.' << MINOR_VERSION << EOL
<< "The Base Framework (Test Suite)" << EOL
<< ENDL;
case 0:
break;
case 1:
service = arguments[0];
break;
case 2:
address = arguments[0];
service = arguments[1];
break;
default:
fout << "server [address] [service]" << ENDL;
return;
}
server(address, service);
}
};
APPLICATION_STUB(ServerApplication);