Logo ROOT   6.14/05
Reference Guide
pserv.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_net
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 ///
11 /// \macro_code
12 ///
13 /// \author Fons Rademakers
14 
15 void pserv()
16 {
17  // Open a parallel server socket looking for connections on a named
18  // service or on a specified port.
19  //TPServerSocket *ss = new TServerSocket("rootserv", kTRUE);
20  TPServerSocket *ss = new TPServerSocket(9090, kTRUE);
21 
22  // Accept a connection and return a full-duplex communication socket.
23  TPSocket *sock = ss->Accept();
24  delete ss;
25 
26  int niter, bsize;
27  sock->Recv(niter, bsize);
28 
29  printf("Receive %d buffers of %d bytes over %d parallel sockets...\n",
30  niter, bsize, sock->GetSize());
31 
32  char *buf = new char[bsize];
33 
34  // start timer
35  TStopwatch timer;
36  timer.Start();
37 
38  // accept data from client
39  for (int i = 0; i < niter; i++) {
40  memset(buf, 0, bsize);
41  int ret = sock->RecvRaw(buf, bsize);
42  if (ret < 0) {
43  printf("error receiving\n");
44  break;
45  }
46  if (buf[0] != 65) {
47  printf("received data corrupted\n");
48  break;
49  }
50  }
51 
52  delete sock;
53  delete [] buf;
54 
55  // stop timer and print results
56  timer.Stop();
57  Double_t rtime = timer.RealTime();
58  Double_t ctime = timer.CpuTime();
59 
60  printf("%d bytes received in %f seconds\n", niter*bsize, rtime);
61  if (rtime > 0) printf("%5.2f MB/s\n", Double_t(niter*bsize/1024/1024)/rtime);
62 }
Double_t RealTime()
Stop the stopwatch (if it is running) and return the realtime (in seconds) passed between the start a...
Definition: TStopwatch.cxx:110
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
Definition: TStopwatch.cxx:58
Double_t CpuTime()
Stop the stopwatch (if it is running) and return the cputime (in seconds) passed between the start an...
Definition: TStopwatch.cxx:125
Int_t GetSize() const
Definition: TPSocket.h:83
void Stop()
Stop the stopwatch.
Definition: TStopwatch.cxx:77
Int_t RecvRaw(void *buffer, Int_t length, ESendRecvOptions opt)
Send a raw buffer of specified length.
Definition: TPSocket.cxx:688
double Double_t
Definition: RtypesCore.h:55
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: RtypesCore.h:87
Stopwatch class.
Definition: TStopwatch.h:28