1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
#ifndef MESSAGE_
#define MESSAGE_
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
//Pseudo code for client/server end
//string host = "localhost";
//int port = 9502;
// username and password
//string username = "admin";
//string password = "password123";
class sendchatMessage {
private:
string originator, recipient;
string message;
size_t body_length_;
public:
enum { header_length = 4 };
enum { max_body_length = 512 };
sendchatMessage(const string orig, const string recip, string msg, size_t
body = 0): originator(orig), recipient(recip), message(msg),
body_length_(body) {
cout<<msg.length()<<'\n';
if(msg.length() <= max_body_length){
//do what you gotta do
cout<<"OK message size"<<'\n';
}else{
//create a new string
//or throw an error.
body_length_ = max_body_length;
cout<<"error in message size"<<'\n';
}
}
};
class recievechatMessage{
private:
public:
recievechatMessage(){
}
void display(){
cout << "Print the message";
}
};
int main()
{
//static for now, should be dynamic
string orig_nickname, recip_nickname;
string answer;
cout << "write something" << '\n';
getline (cin, answer);
cout << answer;
int bodylength = answer.length();
sendchatMessage chat1(orig_nickname, recip_nickname, answer, bodylength);
}
#endif //MESSAGE_
|