#include #include #include #include #include #include #include #include using namespace std; int hclient_mod(void) { // Create canvas and pad to display the histogram TCanvas *c1 = new TCanvas("c1","Histogram sent",200,10,600,480); c1->Draw(); // Open connection to server TSocket *sock = new TSocket("localhost", 9090); // Wait till we get the start message char str[32]; sock->Recv(str, 32); TH1F *hpx = 0; int updates = 0; // Create the histogram const int NBINS = 10; hpx = new TH1F("hpx","This is the px distribution",NBINS,-4,4); char bin_label[1024]; for(int i = 1; i <= NBINS; ++i) { sprintf(bin_label, "bin no. %d", i); hpx->GetXaxis()->SetBinLabel(i, bin_label); } hpx->SetFillColor(48); // set nice fillcolor hpx->SetFillStyle(0); TMessage mess(kMESS_OBJECT); // Fill histogram randomly gRandom->SetSeed(); Float_t px; bool stay_in_loop = true; while(stay_in_loop) { for(int i = 0; i != 100; ++i) { px = gRandom->Gaus(0, 1); hpx->Fill(px); } mess.Reset(); // re-use TMessage object mess.WriteObject(hpx); // write object in message buffer sock->Send(mess); // send message ++updates; hpx->Draw(); c1->Modified(); c1->Update(); cout << " # of updates = " << updates << endl; gSystem->Sleep(1000); // wait for 1 sec } // infinite loop // we get here only if we break out of the loop sock->Close(); // close the socket return 0; }