Logo
~Sockets~
~Examples~
~Contact~


ServerSocket.cpp

Go to the documentation of this file.
00001 //#include <stdio.h>
00002 
00003 #include "ServerSocket.h"
00004 
00005 
00006 
00007 
00008 ServerSocket::ServerSocket(ISocketHandler& h)
00009 :TcpSocket(h)
00010 {
00011         SetLineProtocol();
00012 }
00013 
00014 
00015 ServerSocket::~ServerSocket()
00016 {
00017 }
00018 
00019 
00020 void ServerSocket::OnLine(const std::string& cmd)
00021 {
00022         if (cmd == "QUIT")
00023         {
00024                 Send("BYE\n\n");
00025                 SetCloseAndDelete();
00026         }
00027         else
00028         if (cmd == "TIME")
00029         {
00030                 time_t t = time(NULL);
00031                 struct tm* tp = localtime(&t);
00032                 char datetime[40];
00033                 sprintf(datetime,"%d-%02d-%02d %02d:%02d:%02d",
00034                         tp -> tm_year + 1900,
00035                         tp -> tm_mon + 1,
00036                         tp -> tm_mday,
00037                         tp -> tm_hour,
00038                         tp -> tm_min,
00039                         tp -> tm_sec);
00040                 std::string reply = "TIME: ";
00041                 reply += datetime;
00042                 reply += "\n";
00043                 for (int i = 0; i < 10; i++)
00044                         Send(reply);
00045                 Send("\n");
00046         }
00047         else
00048         if (cmd == "HELP")
00049         {
00050                 Send("Commands supported: QUIT TIME HELP\n\n");
00051         }
00052         else
00053         {
00054                 Send("404 Not found\n\n");
00055         }
00056 }
00057 
00058 
Page, code, and content Copyright (C) 2006 by Anders Hedström
Generated on Mon Aug 29 20:21:47 2005 for C++ Sockets by  doxygen 1.4.4