Example of Server-Socket communication

{
   // Open a server socket looking for connections on a named service or
   // on a specified port.

   //TServerSocket *ss = new TServerSocket("rootserv", kTRUE);
   TServerSocket *ss = new TServerSocket(9090, kTRUE);

   // Accept a connection and return a full-duplex communication socket.
   TSocket *s = ss->Accept();

   // Close the server socket (unless we will use it later to wait for
   // another connection).
   ss->Close();

   // Check some socket options.
   int val;
   s.GetOption(kSendBuffer, &val);
   printf("sendbuffer size: %d\n", val);
   s.GetOption(kRecvBuffer, &val);
   printf("recvbuffer size: %d\n", val);

   // Get the local and remote addresses (informational only).
   TInetAddress adr = s->GetLocalInetAddress();
   adr.Print();
   adr = s->GetInetAddress()
   adr.Print();

   // Start a loop to receive the different messages. Use on if or switch
   // statement to handle each message appropriately.
   int kind;
   char str[256];
   while (1) {
      s->Recv(str, sizeof(str), &kind);
      if (kind == kMESS_CINT) {
         printf("kMESS_CINT: %s\n", str);
         gROOT->ProcessLine(str);
      } else
         printf("%s\n", str);
   }

   // Close the socket.
   s->Close();
}


ROOT page - Class index - Top of the page

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.