#include using std::ostream; #include #include #include #include #include #include #include #include //_________________________________________________________________________________________ class ClientRoot : public TObject{ private: TSocket *sock; char str[1024]; char fName[256]; bool fIsOpen; public: ClientRoot(char* host ="localhost"); ~ClientRoot(); virtual bool TestServer(); virtual TH1* GetSpectrum(); virtual void Open(); virtual void Close(); private: void InitClient(); virtual TH1* ReceiveSpectrum(); ClassDef ( ClientRoot,1); // Nerwork ROOT Client to Receive spectra }; ClassImp(ClientRoot); //_________________________________________________________________________________________ ClientRoot::ClientRoot(char* host) { fIsOpen =false; strcpy (fName,host); cout<< "Client vers : "<< fName <<"\n"; } //_________________________________________________________________________________________ ClientRoot::~ClientRoot(){} //_________________________________________________________________________________________ TH1* ClientRoot::GetSpectrum() { //return the histogram with "histoname" char cmd[256]; char *word; TH1 * h1=NULL; char command[256]; strcpy (command,"MESSAGE HISTO "); strcpy (cmd,command); if(!fIsOpen) { cout<<"\t*** any connected server ! ***\n"; return(NULL); }else{ cout << " Send command : "<Send(command); h1= ReceiveSpectrum(); return(h1); } cout << "Error in GetSpectrum\n"; return(NULL); } } //_________________________________________________________________________________________ TH1* ClientRoot::ReceiveSpectrum() { TH1 *h =NULL; //pointeur sur l'histo à recevoir; TMessage *message =NULL; sock->Recv(message); if (message ) { if (message->What()==kMESS_STRING){ message->ReadString(str,sizeof(str)); if(strcmp(str,"MESSAGE_NO")) { cout<<" No spectrum with this name\n"; delete message; return (NULL); } if(strcmp(str,"MESSAGE_SPECTRA_NOT_READY")) { cout<<" No ready spectrum on server\n"; delete message; return (NULL); } cout << "Error of message in ReceiveSpectrum \n"; delete message; return (NULL); } if(message->GetClass()->InheritsFrom(TH1::Class())) { h = (TH1*)message->ReadObject(message->GetClass()); cout << "\n DONE\n"; delete message; return (h); } } cout << "ERROR DONE in ReceiveSpectrum \n"; return (NULL); } //_________________________________________________________________________________________ void ClientRoot::Open() { //set and start network root server sock=NULL; if (strcmp (fName,"")==0) { cout <<" Root device name not valid!\n"; return; } if (!fIsOpen){ fIsOpen = true; sock=NULL; sock = new TSocket(fName,9090); if (sock){ cout << " Connection to : "<< fName <<" done \n"; fIsOpen = true; }else{ cout<<" Error in connection to : "<< fName <<" \n"; } } } //_________________________________________________________________________________________ void ClientRoot::Close() { if (fIsOpen){ //set and start network root server sock->Close(); fIsOpen =false; } } //_________________________________________________________________________________________ bool ClientRoot::TestServer() { // test server // return is true if server seem to be good and started // else return is false char *command ="MESSAGE TEST"; char cmd[256]; char *word; bool retour = false; strcpy (cmd,command); // we suppose that connexion is open if(!fIsOpen) { cout<<"\t*** any connected server ! ***\n"; return(retour); } else{ //Get GROUP command word word = strtok (cmd," "); if (strcmp(word,"MESSAGE")!=0) { cout<< " It is not a MESSAGE Net commmand group ! "<Send(command); char message[64]; message[0]= '\0';//initialisation sock->Recv(message, sizeof(message)); if (strcmp(message,"MESSAGE_TESTOK")==0) { cout <<" Retour recu = MESSAGE_TESTOK\n"; retour = true; } else { Close(); retour = false; } } } return(retour); } //_________________________________________________________________________________________