ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
pserv.C
Go to the documentation of this file.
1 void pserv()
2 {
3  // Server program to test parallel sockets.
4  //
5  // To run this demo do the following:
6  // - Open two windows
7  // - Start ROOT in all two windows
8  // - Execute in the first window: .x pserv.C
9  // - Execute in the second window: .x pclient.C
10  //Author: Fons Rademakers
11 
12  // Open a parallel server socket looking for connections on a named
13  // service or on a specified port.
14  //TPServerSocket *ss = new TServerSocket("rootserv", kTRUE);
15  TPServerSocket *ss = new TPServerSocket(9090, kTRUE);
16 
17  // Accept a connection and return a full-duplex communication socket.
18  TPSocket *sock = ss->Accept();
19  delete ss;
20 
21  int niter, bsize;
22  sock->Recv(niter, bsize);
23 
24  printf("Receive %d buffers of %d bytes over %d parallel sockets...\n",
25  niter, bsize, sock->GetSize());
26 
27  char *buf = new char[bsize];
28 
29  // start timer
31  timer.Start();
32 
33  // accept data from client
34  for (int i = 0; i < niter; i++) {
35  memset(buf, 0, bsize);
36  int ret = sock->RecvRaw(buf, bsize);
37  if (ret < 0) {
38  printf("error receiving\n");
39  break;
40  }
41  if (buf[0] != 65) {
42  printf("received data corrupted\n");
43  break;
44  }
45  }
46 
47  delete sock;
48  delete [] buf;
49 
50  // stop timer and print results
51  timer.Stop();
52  Double_t rtime = timer.RealTime();
53  Double_t ctime = timer.CpuTime();
54 
55  printf("%d bytes received in %f seconds\n", niter*bsize, rtime);
56  if (rtime > 0) printf("%5.2f MB/s\n", Double_t(niter*bsize/1024/1024)/rtime);
57 }
TServerSocket * ss
Definition: hserv2.C:30
Double_t RealTime()
Stop the stopwatch (if it is running) and return the realtime (in seconds) passed between the start a...
Definition: TStopwatch.cxx:108
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
Definition: TStopwatch.cxx:56
void pserv()
Definition: pserv.C:1
Double_t CpuTime()
Stop the stopwatch (if it is running) and return the cputime (in seconds) passed between the start an...
Definition: TStopwatch.cxx:123
TStopwatch timer
Definition: pirndm.C:37
void Stop()
Stop the stopwatch.
Definition: TStopwatch.cxx:75
Int_t bsize[]
Definition: SparseFit4.cxx:31
Int_t RecvRaw(void *buffer, Int_t length, ESendRecvOptions opt)
Send a raw buffer of specified length.
Definition: TPSocket.cxx:688
Int_t GetSize() const
Definition: TPSocket.h:85
double Double_t
Definition: RtypesCore.h:55
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
Int_t Recv(TMessage *&mess)
Receive a TMessage object.
Definition: TPSocket.cxx:635
virtual TSocket * Accept(UChar_t Opt=kSrvNoAuth)
Accept a connection on a parallel server socket.
const Bool_t kTRUE
Definition: Rtypes.h:91
Stopwatch class.
Definition: TStopwatch.h:30