#include <mcs.hh>
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. cli->exec(MCS_CMD_GETDATA); 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 7562 of file mcs.hh.
Public Member Functions | |
int | chunksize () |
Return the server side chunk size used to send data across network. | |
int | cid () |
Return the server side client identificator. | |
Client (string path, string server, int port=6523, bool synchro=false, bool SSL=false, unsigned int timeout=10 *60 *1000) | |
Constructor. | |
Client (const Client &) | |
Declared to avoid using of default copy constructor. | |
virtual void | event (int op, Data d, int code=0) |
bool | exec (string cmd, Data *data=NULL) |
Execute commands on the server. | |
bool | isConnected () |
Tell if the object is connected to the MCS server. | |
bool | login (string user, string pass, string db="") |
Log in to a MCS server. | |
Client & | operator= (const Client &) |
Declared to avoid using of default assignment operator. | |
void | writeToFile (int des) |
virtual | ~Client () |
Destructor. | |
Public Attributes | |
Record | aux |
Record containing all auxiliary fields sent by the server. | |
Record | code |
Record containing all reply's numeric codes sent by the server while executing the last command. | |
Record | msg |
Record containing all reply's messages sent by the server while executing the last command. | |
Record | out |
Record containing all output lines (code: MSG_OUT) sent by the server while executing the last command. | |
Record | recv |
Record containing all Data objects sent by the server. | |
Protected Member Functions | |
void | clearRecords () |
Clear all records. | |
bool | fetch (unsigned int newpos, bool random) |
Protected Attributes | |
bool | connected |
Flag telling if the client is connected or not. | |
int | fileDescriptor |
int | lchunksize |
int | lcid |
string | lpath |
Local path to read/write files. | |
Record * | lrecord |
bool | writetofile |
mcs::Client::Client | ( | const Client & | ) |
Declared to avoid using of default copy constructor.
mcs::Client::Client | ( | string | path, | |
string | server, | |||
int | port = 6523 , |
|||
bool | synchro = false , |
|||
bool | SSL = false , |
|||
unsigned int | timeout = 10 * 60 * 1000 | |||
) |
Constructor.
path | Local directory; | |
server | Address of a host running a MCS server; | |
port | Port in which the MCS service is listening; | |
synchro | If all Record objects must be synchronized (useful in multithreading application); | |
SSL | If the TCP connection should be protected with SSL; | |
timeout | Time to wait for server response (in milliseconds). |
int mcs::Client::chunksize | ( | ) |
int mcs::Client::cid | ( | ) |
void mcs::Client::clearRecords | ( | ) | [protected] |
bool mcs::Client::exec | ( | string | cmd, | |
Data * | data = NULL | |||
) |
bool mcs::Client::isConnected | ( | ) |
bool mcs::Client::login | ( | string | user, | |
string | pass, | |||
string | db = "" | |||
) |
Declared to avoid using of default assignment operator.
Record containing all reply's numeric codes sent by the server while executing the last command.
Reimplemented from mcs::RecordSet.
bool mcs::Client::connected [protected] |
string mcs::Client::lpath [protected] |
![]() |
MCS (My Customizable Server) ver. 0.3.3-alpha3
|