mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-26 22:03:35 -06:00
reorganizing repo
git-svn-id: svn://ultimatepp.org/upp/trunk@9206 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
7d17505cfe
commit
e3e8d627f5
3840 changed files with 0 additions and 1161578 deletions
|
|
@ -1,151 +0,0 @@
|
|||
#include <Core/Core.h>
|
||||
|
||||
#include <Web/Web.h>
|
||||
|
||||
#include <CmdLineArgProcessor/ArgProcessor.hpp>
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
|
||||
|
||||
bool run=true;
|
||||
|
||||
|
||||
|
||||
void sighandler(int sig)
|
||||
|
||||
{
|
||||
|
||||
run=false;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
CONSOLE_APP_MAIN
|
||||
|
||||
{
|
||||
|
||||
signal(SIGABRT, sighandler);
|
||||
|
||||
signal(SIGINT, sighandler);
|
||||
|
||||
signal(SIGTERM, sighandler);
|
||||
|
||||
int port = 7755;
|
||||
|
||||
|
||||
|
||||
const Vector<String>& cmdline = CommandLine();
|
||||
|
||||
ArgProcessor ap("Test Application", "0.1");
|
||||
|
||||
Arg<bool> server_arg("Server","Specify to set program to server mode.", false);
|
||||
|
||||
Arg<String> host_arg("Destination", "Destination to connect to (client mode).", false);
|
||||
|
||||
ArgSet client_args, server_args;
|
||||
|
||||
client_args.AddArg(host_arg);
|
||||
|
||||
server_args.AddArg(server_arg);
|
||||
|
||||
ap.AddArgSet(client_args);
|
||||
|
||||
ap.AddArgSet(server_args);
|
||||
|
||||
ap.PrintUsageOnError();
|
||||
|
||||
ap.ProcessCmdLine(cmdline);
|
||||
|
||||
|
||||
|
||||
if(!ap.IsError())
|
||||
|
||||
{
|
||||
|
||||
String host;
|
||||
|
||||
if(host_arg.IsSet())
|
||||
|
||||
{
|
||||
|
||||
host = host_arg.Val();
|
||||
|
||||
}
|
||||
|
||||
else
|
||||
|
||||
{
|
||||
|
||||
host = "localhost";
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(!server_arg.IsSet())
|
||||
|
||||
{
|
||||
|
||||
Socket s1;
|
||||
|
||||
if( ClientSocket(s1,host,port) )
|
||||
|
||||
{
|
||||
|
||||
s1.Write("Hello World!");
|
||||
|
||||
s1.Close();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
else
|
||||
|
||||
{
|
||||
|
||||
Cout() << "Server started. Press Ctrl-C to exit.\n";
|
||||
|
||||
Socket accept_socket, data_socket;
|
||||
|
||||
ServerSocket(accept_socket,port);
|
||||
|
||||
while(run)
|
||||
|
||||
{
|
||||
|
||||
dword ipaddr;
|
||||
|
||||
if( accept_socket.Accept(data_socket, &ipaddr) )
|
||||
|
||||
{
|
||||
|
||||
Cout() << "Connection from " << FormatIP(m_ipaddr) << "\n";
|
||||
|
||||
while(data_socket.IsOpen() && !data_socket.IsError() && !data_socket.IsEof())
|
||||
|
||||
{
|
||||
|
||||
Cout() << data_socket.Read();
|
||||
|
||||
}
|
||||
|
||||
Cout() << "\n";
|
||||
|
||||
data_socket.Close();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
accept_socket.Close();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue