MCS  0.3.3-alpha7
mcs::Client Class Reference

Connect to a MCS server as a client. More...

#include <mcs.hh>

+ Inheritance diagram for mcs::Client:

Public Member Functions

int chunksize ()
 Return the server side chunk size used to send data across network. More...
 
int cid ()
 Return the server side client identificator. More...
 
 Client (const Client &)
 Declared to avoid using of default copy constructor. More...
 
 Client (string path, string server, int port=6523, bool synchro=false, bool SSL=false, unsigned int timeout=10 *60 *1000)
 Constructor. More...
 
virtual void event (int op, Data d, int code=0)
 
bool exec (string cmd, Data *data=NULL)
 Execute commands on the server. More...
 
bool isConnected ()
 Tell if the object is connected to the MCS server. More...
 
bool login (string user, string pass, string db="")
 Log in to a MCS server. More...
 
Clientoperator= (const Client &)
 Declared to avoid using of default assignment operator. More...
 
void writeToFile (int des)
 
virtual ~Client ()
 Destructor. More...
 
- Public Member Functions inherited from mcs::Socket
void Close ()
 Close the socket. More...
 
string getline ()
 Reads from a socket until a newline is encountered. More...
 
Socketoperator= (const Socket &)
 Declared to avoid using of default assignment operator. More...
 
void print (string s)
 Writes a string in the socket adding a newline. More...
 
unsigned int read (void *buf, unsigned int count)
 Reads data from the socket and write in a buffer. More...
 
unsigned int recvData (char **buffer, unsigned int maxsize)
 Receive data and store in a buffer. More...
 
unsigned int recvData (string filename)
 Receive data and write to a file. More...
 
unsigned int recvData (int filedes)
 Receive data and write to a file descriptor. More...
 
unsigned int recvData (ofstream &stream)
 Receive data and write to a ofstream object. More...
 
void sendData (Serializable *from)
 Send a block of data through the socket. More...
 
 Socket (const Socket &)
 Declared to avoid using of default copy constructor. More...
 
 Socket (string host, unsigned short int port=0, unsigned int readTimeout=1000, unsigned int writeTimeout=1000, bool ssl=false)
 Constructor, to create a new connection. More...
 
 Socket (int sockfd, unsigned int readTimeout=1000, unsigned int writeTimeout=1000, void *ssl_ctx=NULL)
 Constructor based on an already existent socket. More...
 
unsigned int write (void *buf, unsigned int count)
 Reads data from a buffer and write in the socket. More...
 
 ~Socket ()
 Destructor. More...
 
- Public Member Functions inherited from mcs::HostInfo
 HostInfo (const HostInfo &)
 Declared to avoid using of default copy constructor. More...
 
 HostInfo (string host)
 Constructor. More...
 
 HostInfo (int sockfd)
 Constructor, to obtain information from an already connected socket. More...
 
string hostname ()
 Return the host name. More...
 
string ipaddress ()
 Return the host IP address. More...
 
HostInfooperator= (const HostInfo &)
 Declared to avoid using of default assignment operator. More...
 
 ~HostInfo ()
 Destructor. More...
 
- Public Member Functions inherited from mcs::RecordSet
bool alwaysSameStructure ()
 
void dump (string fn)
 
bool eof ()
 
void insert (Record *rec)
 Insert a new record in the set. More...
 
void insert (Record &rec)
 Copy a new record in the set. More...
 
bool know_nRows ()
 
Recordmetarec ()
 
int nFields ()
 Returns number of fields. More...
 
unsigned int nRows ()
 
RecordSetoperator= (const RecordSet &)
 Declared to avoid using of default assignment operator. More...
 
unsigned int pos ()
 
RecordprepRecToSend ()
 
Recordrec ()
 
 RecordSet (const RecordSet &)
 Declared to avoid using of default copy constructor. More...
 
 RecordSet ()
 Build an empty record set. More...
 
void setFieldMap (string s="")
 Set up a field map for each record in the recordset. More...
 
bool setFirst ()
 Set the record pointer to the first position. More...
 
bool setLast ()
 Set the record pointer to the last position. More...
 
bool setNext ()
 Set the record pointer to the next position. More...
 
bool setPos (unsigned int i)
 Set the record pointer to the i-th position. More...
 
bool setPrev ()
 Set the record pointer to the previous position in the set. More...
 
bool setWhere (int i, string equalTo)
 Set the record pointer to the position which satisfies a string condition. More...
 
bool setWhere (int field, int equalTo)
 Set the record pointer to the position which satisfies an integer condition. More...
 
virtual ~RecordSet ()
 Destructor. More...
 

Public Attributes

Record aux
 Record containing all auxiliary fields sent by the server. More...
 
Record code
 Record containing all reply's numeric codes sent by the server while executing the last command. More...
 
Record msg
 Record containing all reply's messages sent by the server while executing the last command. More...
 
Record out
 Record containing all output lines (code: MSG_OUT) sent by the server while executing the last command. More...
 
Record recv
 Record containing all Data objects sent by the server. More...
 

Protected Member Functions

void clearRecords ()
 Clear all records. More...
 
bool fetch (unsigned int newpos, bool random)
 
- Protected Member Functions inherited from mcs::Socket
bool chkRecv (bool chkDataAvailable=false, enum ThrowExceptions throwexc=THROW)
 Check if you can read data from this socket. More...
 
bool chkSend (enum ThrowExceptions throwexc=THROW)
 Check if you can send data through this socket. More...
 
- Protected Member Functions inherited from mcs::HostInfo
void populate_sockaddr_in ()
 
- Protected Member Functions inherited from mcs::RecordSet
virtual void hk_dump (string fn)
 Virtual method to provide dump facility to a file. More...
 
void init (unsigned char code, unsigned int nrows=0, Record *meta=NULL, short int id=0)
 Initailize the Record set. More...
 
void startFetch ()
 Must be called when record fetching is possible. More...
 

Protected Attributes

bool connected
 Flag telling if the client is connected or not. More...
 
int fileDescriptor
 
int lchunksize
 
int lcid
 
string lpath
 Local path to read/write files. More...
 
Recordlrecord
 
bool writetofile
 
- Protected Attributes inherited from mcs::HostInfo
string host
 
string ipaddr
 
struct sockaddr_in sin
 

Additional Inherited Members

- Static Public Member Functions inherited from mcs::Socket
static void set_struct_timeval (unsigned int millisec, struct timeval *time)
 Fill a "struct timeval" with the given interval. More...
 

Detailed Description

Connect to a MCS server as a client.

This class let you connect to a MCS server as a client, execute command on it, upload and download files and binary data. A typical usage is as follow:

#include <mcs.hh>
using namespace mcs;
...
try {
//Connect to the server.
Client cli = new Client("", "Host_running_a_MCS_server");
//Login
cli->login(user, pass, dbna);
//Retrieve the Client Identifier
cli->exec("cid");
int cid = cli->recv.pop().ival();
//Query a table in the database
if (! cli->exec(MCS_CMD_QUERY + string(" SELECT * FROM MyTable")))
{
//The server reported an error
while (cli->msg.ready())
cout << cli->msg.pop().sval() << endl;
exit(1);
}
//Retrieve the first record
cli->exec(MCS_CMD_RECORD + string (" 0"));
//Use values in field...
cli->record()[0].ival();
cli->record().field("MyField").sval();
//...
//Create an INTEGER Data object to send to server.
Data aa(12);
cli->exec(MCS_CMD_PUTDATA, &aa);
//Retrieve a Data object from the server.
Data bb = cli->recv.pop();
//Upload a file
cli->exec(MCS_CMD_PUT + string(" FileToUpload");
//Download a file
cli->exec(MCS_CMD_GET + string(" FileToDownload");
//Close connection
cli->exec(MSG_BYE);
}
catch (Event e) {
cout << e.msg() << endl;
}

Definition at line 7538 of file mcs.hh.

Constructor & Destructor Documentation

◆ Client() [1/2]

mcs::Client::Client ( const Client )

Declared to avoid using of default copy constructor.

Warning
This constructor is declared but not implemented. If you try to use it you will get a compilation error.

◆ Client() [2/2]

mcs::Client::Client ( string  path,
string  server,
int  port = 6523,
bool  synchro = false,
bool  SSL = false,
unsigned int  timeout = 10 * 60 * 1000 
)

Constructor.

Parameters
pathLocal directory;
serverAddress of a host running a MCS server;
portPort in which the MCS service is listening;
synchroIf all Record objects must be synchronized (useful in multithreading application);
SSLIf the TCP connection should be protected with SSL;
timeoutTime to wait for server response (in milliseconds).

Definition at line 29 of file Client.cc.

◆ ~Client()

mcs::Client::~Client ( )
virtual

Destructor.

Definition at line 63 of file Client.cc.

Member Function Documentation

◆ chunksize()

int mcs::Client::chunksize ( )

Return the server side chunk size used to send data across network.

Definition at line 332 of file Client.cc.

◆ cid()

int mcs::Client::cid ( )

Return the server side client identificator.

Definition at line 329 of file Client.cc.

◆ clearRecords()

void mcs::Client::clearRecords ( )
protected

Clear all records.

Definition at line 101 of file Client.cc.

◆ exec()

bool mcs::Client::exec ( string  cmd,
Data data = NULL 
)

Execute commands on the server.

Parameters
cmdThe command to execute;
DataIf the command is MCS_CMD_PUTDATA you should supply an address to a valid Data object;

Definition at line 124 of file Client.cc.

◆ isConnected()

bool mcs::Client::isConnected ( )

Tell if the object is connected to the MCS server.

Definition at line 322 of file Client.cc.

◆ login()

bool mcs::Client::login ( string  user,
string  pass,
string  db = "" 
)

Log in to a MCS server.

You must already been connected (see the constructor) to the host before executing this method.

Parameters
userUser name;
passPassword;
dbDatabase name, default is the application name.
Returns
True if logged in, false otherwise.

Definition at line 76 of file Client.cc.

◆ operator=()

Client& mcs::Client::operator= ( const Client )

Declared to avoid using of default assignment operator.

Warning
This operator is declared but not implemented. If you try to use it you will get a compilation error.

Member Data Documentation

◆ aux

Record mcs::Client::aux

Record containing all auxiliary fields sent by the server.

Definition at line 7604 of file mcs.hh.

◆ code

Record mcs::Client::code

Record containing all reply's numeric codes sent by the server while executing the last command.

Definition at line 7579 of file mcs.hh.

◆ connected

bool mcs::Client::connected
protected

Flag telling if the client is connected or not.

Definition at line 7545 of file mcs.hh.

◆ lpath

string mcs::Client::lpath
protected

Local path to read/write files.

Definition at line 7542 of file mcs.hh.

◆ msg

Record mcs::Client::msg

Record containing all reply's messages sent by the server while executing the last command.

Definition at line 7592 of file mcs.hh.

◆ out

Record mcs::Client::out

Record containing all output lines (code: MSG_OUT) sent by the server while executing the last command.

Definition at line 7598 of file mcs.hh.

◆ recv

Record mcs::Client::recv

Record containing all Data objects sent by the server.

Definition at line 7601 of file mcs.hh.


The documentation for this class was generated from the following files:

mcslogo

MCS (My Customizable Server) ver. 0.3.3-alpha7
Documentation generated on Mon May 28 07:39:41 UTC 2018