ROOT logo

From $ROOTSYS/tutorials/net/pserv.C

void pserv()
{
   // Server program to test parallel sockets.
   //
   // To run this demo do the following:
   //   - Open two windows
   //   - Start ROOT in all two windows
   //   - Execute in the first window: .x pserv.C
   //   - Execute in the second window: .x pclient.C
   //Author: Fons Rademakers
   
   // Open a parallel server socket looking for connections on a named
   // service or on a specified port.
   //TPServerSocket *ss = new TServerSocket("rootserv", kTRUE);
   TPServerSocket *ss = new TPServerSocket(9090, kTRUE);

   // Accept a connection and return a full-duplex communication socket.
   TPSocket *sock = ss->Accept();
   delete ss;

   int niter, bsize;
   sock->Recv(niter, bsize);

   printf("Receive %d buffers of %d bytes over %d parallel sockets...\n",
          niter, bsize, sock->GetSize());

   char *buf = new char[bsize];

   // start timer
   TStopwatch timer;
   timer.Start();

   // accept data from client
   for (int i = 0; i < niter; i++) {
      memset(buf, 0, bsize);
      int ret = sock->RecvRaw(buf, bsize);
      if (ret < 0) {
         printf("error receiving\n");
         break;
      }
      if (buf[0] != 65) {
         printf("received data corrupted\n");
         break;
      }
   }

   delete sock;
   delete [] buf;

   // stop timer and print results
   timer.Stop();
   Double_t rtime = timer.RealTime();
   Double_t ctime = timer.CpuTime();

   printf("%d bytes received in %f seconds\n", niter*bsize, rtime);
   if (rtime > 0) printf("%5.2f MB/s\n", Double_t(niter*bsize/1024/1024)/rtime);
}
 pserv.C:1
 pserv.C:2
 pserv.C:3
 pserv.C:4
 pserv.C:5
 pserv.C:6
 pserv.C:7
 pserv.C:8
 pserv.C:9
 pserv.C:10
 pserv.C:11
 pserv.C:12
 pserv.C:13
 pserv.C:14
 pserv.C:15
 pserv.C:16
 pserv.C:17
 pserv.C:18
 pserv.C:19
 pserv.C:20
 pserv.C:21
 pserv.C:22
 pserv.C:23
 pserv.C:24
 pserv.C:25
 pserv.C:26
 pserv.C:27
 pserv.C:28
 pserv.C:29
 pserv.C:30
 pserv.C:31
 pserv.C:32
 pserv.C:33
 pserv.C:34
 pserv.C:35
 pserv.C:36
 pserv.C:37
 pserv.C:38
 pserv.C:39
 pserv.C:40
 pserv.C:41
 pserv.C:42
 pserv.C:43
 pserv.C:44
 pserv.C:45
 pserv.C:46
 pserv.C:47
 pserv.C:48
 pserv.C:49
 pserv.C:50
 pserv.C:51
 pserv.C:52
 pserv.C:53
 pserv.C:54
 pserv.C:55
 pserv.C:56
 pserv.C:57
 pserv.C:58