class SpyServ {
private:
public:
   SpyServ();
   ~SpyServ();
 
};
 
 
void SpyServ::HandleSocket(
TSocket *s)
 
{
      
      fMon->Add(sock);
      fSockets->Add(sock);
   } else {
      
      char request[64];
      if (s->
Recv(request, 
sizeof(request)) <= 0) {
 
         fMon->Remove(s);
         fSockets->Remove(s);
         delete s;
         return;
      }
 
      
      if (!strcmp(request, "get hpx"))
         answer.WriteObject(fHpx);
      else if (!strcmp(request, "get hpxpy"))
         answer.WriteObject(fHpxpy);
      else if (!strcmp(request, "get hprof"))
         answer.WriteObject(fHprof);
      else
         Error(
"SpyServ::HandleSocket", 
"unexpected message");
 
   }
}
 
SpyServ::SpyServ()
{
   
   
   
 
   
   
   
   if (!fServ->IsValid())
 
   
   
 
   
 
   
   fCanvas = 
new TCanvas(
"SpyServ",
"SpyServ",200,10,700,500);
 
   fCanvas->SetFillColor(42);
   fCanvas->GetFrame()->SetFillColor(21);
   fCanvas->GetFrame()->SetBorderSize(6);
   fCanvas->GetFrame()->SetBorderMode(-1);
 
   
   fHpx    = 
new TH1F(
"hpx",
"This is the px distribution",100,-4,4);
 
   fHpxpy  = 
new TH2F(
"hpxpy",
"py vs px",40,-4,4,40,-4,4);
 
   fHprof  = 
new TProfile(
"hprof",
"Profile of pz versus px",100,-4,4,0,20);
 
 
   
   fHpx->SetFillColor(48);
 
   
   for (
Int_t i = 0; ; i++) {
 
      pz = px*px + py*py;
      fHpx->Fill(px);
      fHpxpy->Fill(px,py);
      fHprof->Fill(px,pz);
         fCanvas->Modified();
         fCanvas->Update();
 
         
         
         if ((s = fMon->Select(20)) != (
TSocket*)-1)
 
            HandleSocket(s);
            break;
         if (
gROOT->IsInterrupted())
 
            break;
      }
   }
}
 
SpyServ::~SpyServ()
{
   
 
   fSockets->Delete();
   delete fSockets;
   delete fServ;
   delete fCanvas;
   delete fHpx;
   delete fHpxpy;
   delete fHprof;
}
 
void spyserv()
{
   new SpyServ;
}
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
 
R__EXTERN TRandom * gRandom
 
R__EXTERN TSystem * gSystem
 
1-D histogram with a float per channel (see TH1 documentation)}
 
2-D histogram with a float per channel (see TH1 documentation)}
 
const char * GetHostName() const
 
virtual void Add(TSocket *sock, Int_t interest=kRead)
Add socket to the monitor's active list.
 
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
 
virtual void Rannor(Float_t &a, Float_t &b)
Return 2 numbers distributed following a gaussian with mean=0 and sigma=1.
 
virtual Int_t Recv(TMessage *&mess)
Receive a TMessage object.
 
TInetAddress GetInetAddress() const
 
TClass * IsA() const override
 
virtual Int_t Send(const TMessage &mess)
Send a TMessage object.
 
virtual void Exit(int code, Bool_t mode=kTRUE)
Exit the application.
 
R__ALWAYS_INLINE bool HasBeenDeleted(const TObject *obj)
Check if the TObject's memory has been deleted.