Re: Timestamp echo message
What do you mean by "typing "Test""? Looking at your snippit above, I would think that you should be typeing "0004Test".
Re: Timestamp echo message
Hey this is all the code on the page:-
#include <iostream>
#include <string>
#include <sstream>
#include <time.h>
#include <iomanip>
#include <algorithm>
using namespace std;
bool DayTimeServer::run(TCPSocket *connSocket,
sockaddr_in *client_addr)
{
time_t curTime;
string client_ip, timeStr, command_str, msg_str;
int client_port;
int bytesSent, bytesRecv = SOCKET_ERROR;
bool status = true;
client_ip = inet_ntoa(client_addr->sin_addr);
client_port = ntohs(client_addr->sin_port);
cout << "Connection received from IP: "<<client_ip<<endl;
//Read the command first.
command_str = receive(connSocket, 3);
string response; //declare the response
if (command_str.size() > 0){
cout<<"Client's message .. " << command_str <<" .. "; //Notofication
if ( command_str == "ECH")
{
string msg_sz = receive(connSocket, 4);
int size = atoi(msg_sz.c_str());
string msg = receive(connSocket, size);
response = "ECHRP"+msg_sz+msg;
}
else if (command_str == "REV")
{
string msg_sz = receive(connSocket, 4);
int size = atoi(msg_sz.c_str());
string msg = receive(connSocket, size);
std::reverse(msg.begin(),msg.end());
response = "REVRP"+msg_sz+msg;
}
else if (command_str == "TIM")
{
string msg_sz = receive(connSocket, 4);
int size = atoi(msg_sz.c_str());
string msg = receive(connSocket, size);
response = "TIMRP"+msg_sz+msg;
}
else {
timeStr = "UNKNOWN COMMAND";
}
send(connSocket,response);
cout<<"Replied: -> "<<timeStr<<" --"<<endl;
}
return status;
}
string toString (unsigned int val, unsigned short len)
{
stringstream stream;
stream <<setfill('0')<<setw(len)<< val ;
return stream.str();
}
I want to type in "Test" or whatever and i want to be shown the TIMESTAMP of the message and the message itself.
the code in bold is what i am working with...
does this help make you understand what i am trying to do?
Re: Timestamp echo message
Please use [CODE] [/CODE] tags around your code.
The client code would be more helpful (assuming you are "typing" in the client and it is sending it to the server).
It appears that whatever protocol you are using, the server expects to receive a stream composed of a three character command code (i.e. "TIM"), a 4 character "size" value, followed by "size" characters of text.
Without seeing the client code, I assume that the client prompts the user for a string, then formats a "packet" to send to the server so that typing "Test" results in "TIM0004Test" being sent to the server.
Now, what exactly are you trying to accomplish?