13 #include <ecl/config/ecl.hpp>    47 using ecl::SocketServer;
    52 using ecl::MilliSleep;
    61         Reader(SocketServer &socket_server, 
bool timestamps_reqd, 
bool hex_format_reqd, 
const int &port_number) :
    62                 socket(socket_server),
    63                 timestamps(timestamps_reqd),
    71         Format<unsigned char> hex_format(-1,
NoAlign,
Hex);
    76         if ( hex ) { std::cout << 
"Hex format" << std::endl; } 
else { std::cout << 
"Ascii format" << std::endl; }
    79             ch_read = socket.read(c);
    83                         if ( new_line ) { timestamp.stamp(); }
    84                                         std::cout << 
"[" << timestamp << 
"] : ";
    86                     std::cout << hex_format(c) << std::endl;
    88                     if ( timestamps && new_line ) {
    90                                         std::cout << 
"[" << timestamp << 
"] : ";
    98                         } 
else if ( c == 
'\n' ) {
   102             } 
else if ( ch_read < 0 ) {
   104                     std::cout << 
"Client Hung Up." << std::endl;
   116         SocketServer &socket;
   126         Writer(SocketServer &socket_server, 
bool timestamps_reqd) :
   127                 socket(socket_server),
   128                 timestamps(timestamps_reqd)
   134         memset(buffer,0,256);
   137             if ( fgets(buffer,80,stdin) == NULL ) {
   143             while ( *s_ptr != 
'\0') { ++s_ptr; }
   144             if ( timestamps ) { timestamp.stamp(); }
   145             socket.write(buffer,s_ptr - buffer);
   147                 std::cout << 
"[" << timestamp << 
"] : ";
   157         SocketServer &socket;
   175 int main(
int argc, 
char** argv) {
   177     std::cout << std::endl;
   178     std::cout << 
"***********************************************************" << std::endl;
   179     std::cout << 
"                 Parsing Command Line" << std::endl;
   180     std::cout << 
"***********************************************************" << std::endl;
   181     std::cout << std::endl;
   184     bool timestamps(
false);
   187         CmdLine cmd(
"This is a simple interface for making serving from a socket.",
' ',
"0.1");
   188         ValueArg<int> arg_port(
"p",
"port",
"Port to connect to [1470].",
false,1470,
"integer");
   189         SwitchArg switch_hex(
"x",
"hex",
"Enable hex output.",
false);
   190         SwitchArg switch_timestamps(
"t",
"timestamp",
"Timestamp incoming/outgoings.",
false);
   194         cmd.add(switch_timestamps);
   195         cmd.parse(argc,argv);
   197         hex = switch_hex.getValue();
   198         port = arg_port.getValue();
   199         timestamps = switch_timestamps.getValue();
   201     } 
catch ( ArgException &e ) {
   202         std::cerr << 
"error: " << e.error() << 
" for arg " << e.argId() << std::endl;
   205     std::cout << 
"Listening on port: " << port << std::endl;
   207     std::cout << std::endl;
   208     std::cout << 
"***********************************************************" << std::endl;
   209     std::cout << 
"                   Read and Write Threads   " << std::endl;
   210     std::cout << 
"***********************************************************" << std::endl;
   211     std::cout << std::endl;
   213     SocketServer server(port);
   215     Writer writer(server,timestamps);
   216     Reader reader(server,timestamps,hex,port);
   217     Thread read_thread(&Reader::loop, reader);
   218     Thread write_thread(&Writer::loop, writer);
   223     std::cout << std::endl;
   224     std::cout << 
"***********************************************************" << std::endl;
   225     std::cout << 
"                      Passed" << std::endl;
   226     std::cout << 
"***********************************************************" << std::endl;
   227     std::cout << std::endl;
   235 #if !defined ECL_IS_POSIX || ECL_IS_MAC   239 int main(
int argc, 
char **argv) {
   241         std::cout << 
"This is a posix (not mac) only app." << std::endl;
 
int main(int argc, char **argv)