00001 #include "TBenchmark.h"
00002 #include "TList.h"
00003 #include "TInetAddress.h"
00004 #include "TSocket.h"
00005 #include "TMessage.h"
00006 #include "TH1.h"
00007 #include "TH2.h"
00008 #include "TRandom.h"
00009 #include "TBonjourBrowser.h"
00010 #include "TBonjourResolver.h"
00011 #include "TBonjourRecord.h"
00012
00013
00014 static Bool_t gEvo = kFALSE;
00015
00016 void ConnectToServer(const TInetAddress *hostb, Int_t port)
00017 {
00018
00019
00020
00021
00022 TBonjourResolver *resolver = (TBonjourResolver*) gTQSender;
00023 TInetAddress host = *hostb;
00024 delete resolver;
00025
00026 printf("ConnectToServer: host = %s, port = %d\n", host.GetHostName(), port);
00027
00028
00029
00030
00031 TSocket *sock = new TSocket(host.GetHostName(), port);
00032
00033
00034 char str[32];
00035 sock->Recv(str, 32);
00036
00037
00038 int idx = !strcmp(str, "go 0") ? 0 : 1;
00039
00040 Float_t messlen = 0;
00041 Float_t cmesslen = 0;
00042 if (idx == 1)
00043 sock->SetCompressionLevel(1);
00044
00045 TH1 *hpx;
00046 if (idx == 0) {
00047
00048 hpx = new TH1F("hpx","This is the px distribution",100,-4,4);
00049 hpx->SetFillColor(48);
00050 } else {
00051 hpx = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4);
00052 }
00053
00054 TMessage::EnableSchemaEvolutionForAll(gEvo);
00055 TMessage mess(kMESS_OBJECT);
00056
00057
00058
00059 gRandom->SetSeed();
00060 Float_t px, py;
00061 const int kUPDATE = 1000;
00062 for (int i = 0; i < 25000; i++) {
00063 gRandom->Rannor(px,py);
00064 if (idx == 0)
00065 hpx->Fill(px);
00066 else
00067 hpx->Fill(px,py);
00068 if (i && (i%kUPDATE) == 0) {
00069 mess.Reset();
00070 mess.WriteObject(hpx);
00071 sock->Send(mess);
00072 messlen += mess.Length();
00073 cmesslen += mess.CompLength();
00074 }
00075 }
00076 sock->Send("Finished");
00077
00078 if (cmesslen > 0)
00079 printf("Average compression ratio: %g\n", messlen/cmesslen);
00080
00081 gBenchmark->Show("hclient");
00082
00083
00084 sock->Close();
00085 }
00086
00087 void UpdateBonjourRecords(TList *records)
00088 {
00089
00090
00091
00092 static Bool_t resolved = kFALSE;
00093
00094
00095 printf("UpdateBonjourRecords (resolved = %s)\n", resolved ? "kTRUE" : "kFALSE");
00096
00097 if (resolved) return;
00098
00099
00100 TBonjourRecord *rec;
00101 TIter next(records);
00102 while ((rec = (TBonjourRecord*) next())) {
00103 if (!strcmp(rec->GetRegisteredType(), "_hserv2._tcp.") &&
00104 !strcmp(rec->GetReplyDomain(), "local.")) {
00105 rec->Print();
00106 TBonjourResolver *resolver = new TBonjourResolver;
00107 resolver->Connect("RecordResolved(TInetAddress*,Int_t)", 0, 0,
00108 "ConnectToServer(TInetAddress*,Int_t)");
00109 resolver->ResolveBonjourRecord(*rec);
00110 resolved = kTRUE;
00111 }
00112 }
00113 }
00114
00115 void hclientbonj(Bool_t evol=kFALSE)
00116 {
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 gEvo = evol;
00136
00137 gBenchmark->Start("hclient");
00138
00139 TBonjourBrowser *browser = new TBonjourBrowser;
00140 browser->Connect("CurrentBonjourRecordsChanged(TList*)", 0, 0,
00141 "UpdateBonjourRecords(TList*)");
00142 browser->BrowseForServiceType("_hserv2._tcp");
00143 }