Beispiel #1
0
int authserv(int po = 3000)
{

   UChar_t oauth = kSrvAuth;

   TServerSocket *ss = 0;
   TSocket *s = 0;

   cout << "authserv: starting a (parallel) server socket on port "
        << po << " with authentication" << endl;
 
   ss = new TPServerSocket(po);

   // Get the connection
   s = ss->Accept(oauth);

   // Print out;
   if (s) 
      if (s->IsAuthenticated()) 
         cout << "authserv: srv auth socket: OK" << endl;
      else
         cout << "authserv: srv auth socket: failed" << endl;

   // Cleanup
   if (s) delete s;
   if (ss) delete ss;
}
void KVINDRAOnlineDataAnalyser::ecouteSockets(void* arg)
{
   // static method, lance dans un thread
   // listen to the sockets

   TThread::Printf("<KVINDRAOnlineDataAnalyser::ecouteSockets> : beginning thread");
   KVINDRAOnlineDataAnalyser* ANA = (KVINDRAOnlineDataAnalyser*)arg;
   TServerSocket* fServer = new TServerSocket(ANA->port, kTRUE);

   if (!fServer->IsValid()) TThread::Printf("<KVINDRAOnlineDataAnalyser::ecouteSockets> : Port %d not valid", ANA->port);
   TMonitor* fMonitor = new TMonitor;
   fMonitor->Add(fServer);

   while (1) {

      TSocket* ss = fMonitor->Select();
      if (ss <= (TSocket*)0) continue;

      if (ss->IsA() == TServerSocket::Class()) {
         // new connection ?
         TSocket* s0 = fServer->Accept();
         if (s0) {
            TThread::Printf("<KVINDRAOnlineDataAnalyser::ecouteSockets> : Client found at %s",
                            s0->GetInetAddress().GetHostName());
            fMonitor->Add(s0);
         }
         continue;
      }
      if (ss->IsA() != TSocket::Class()) continue;

      TMessage* mess;
      if (ss->Recv(mess) <= 0) {
         // socket has been closed (?)
         TThread::Printf("<KVINDRAOnlineDataAnalyser::ecouteSockets> : connection from %s has been closed", ss->GetInetAddress().GetHostName());
         fMonitor->Remove(ss);
         delete ss;
         continue;
      }

      if (mess->What() == kMESS_STRING) {

         // deal with commands
         char str[256];
         mess->ReadString(str, 256);
         TThread::Printf("<KVINDRAOnlineDataAnalyser::ecouteSockets> : Received: %s", str);
         TString command(str);
         //command.ToUpper();
         ANA->HandleCommands(command, ss);

      }/* else if (mess->What() == kMESS_OBJECT) {
         TThread::Printf("<KVINDRAOnlineDataAnalyser::ecouteSockets> : Received UN P***IN d'OBJET!!!");
      } else {
         TThread::Printf("<KVINDRAOnlineDataAnalyser::ecouteSockets> : *** Unexpected message ***");
      }*/

      delete mess;
   }
}
Beispiel #3
0
Datei: hserv.C Projekt: Y--/root
void hserv() {
   // 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 *s0 = ss->Accept();
   TSocket *s1 = ss->Accept();

   // tell the clients to start
   s0->Send("go 0");
   s1->Send("go 1");

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

   // Check some options of socket 0.
   int val;
   s0->GetOption(kSendBuffer, val);
   printf("sendbuffer size: %d\n", val);
   s0->GetOption(kRecvBuffer, val);
   printf("recvbuffer size: %d\n", val);

   // Get the remote addresses (informational only).
   TInetAddress adr = s0->GetInetAddress();
   adr.Print();
   adr = s1->GetInetAddress();
   adr.Print();

   // Create canvas and pads to display the histograms
   TCanvas *c1 = new TCanvas("c1","The Ntuple canvas",200,10,700,780);
   TPad *pad1 = new TPad("pad1","This is pad1",0.02,0.52,0.98,0.98,21);
   TPad *pad2 = new TPad("pad2","This is pad2",0.02,0.02,0.98,0.48,21);
   pad1->Draw();
   pad2->Draw();

   TMonitor *mon = new TMonitor;

   mon->Add(s0);
   mon->Add(s1);

   while (1) {
      TMessage *mess;
      TSocket  *s;

      s = mon->Select();

      s->Recv(mess);

      if (mess->What() == kMESS_STRING) {
         char str[64];
         mess->ReadString(str, 64);
         printf("Client %d: %s\n", s==s0 ? 0 : 1, str);
         mon->Remove(s);
         if (mon->GetActive() == 0) {
            printf("No more active clients... stopping\n");
            break;
         }
      } else if (mess->What() == kMESS_OBJECT) {
         //printf("got object of class: %s\n", mess->GetClass()->GetName());
         TH1 *h = (TH1 *)mess->ReadObject(mess->GetClass());
         if (h) {
            if (s == s0)
               pad1->cd();
            else
               pad2->cd();
            h->Print();
            h->DrawCopy();  //draw a copy of the histogram, not the histo itself
            c1->Modified();
            c1->Update();
            delete h;       // delete histogram
         }
      } else {
         printf("*** Unexpected message ***\n");
      }

      delete mess;
   }

   printf("Client 0: bytes recv = %d, bytes sent = %d\n", s0->GetBytesRecv(),
          s0->GetBytesSent());
   printf("Client 1: bytes recv = %d, bytes sent = %d\n", s1->GetBytesRecv(),
          s1->GetBytesSent());

   // Close the socket.
   s0->Close();
   s1->Close();
}
Beispiel #4
0
// ______________________________________________
void fzd2bin(const Int_t Nevents=5, const Char_t *fzfile ="muon.fzd",int socketID=9093) {
  Int_t  i=0;

  gSystem->Load("EEmc.so"); 
  gROOT->LoadMacro("bfc.C");
  bfc(0,"fzin sim_T gen_T",fzfile);

#ifdef WRITE_SOCKET
  cout<<"opening socket="<<socketID<<"\n";
  TServerSocket *ss = new TServerSocket(socketID, kTRUE);
  cout<<"waits for client1...\n";
  // Accept a connection and return a full-duplex communication socket.
  TSocket *s0 = ss->Accept();
  cout<<"waits 2...\n";
#endif

  for (i=1; i<=Nevents; i++ ) {
    chain->Clear();
    if (chain->Make(i)>=kStEOF) break;
    printf("%2d ====================================\n",i);
    St_g2t_ctf_hit *emc_hit = (St_g2t_ctf_hit *) chain->FindObject("g2t_eem_hit");
    if (emc_hit==0) continue;

#ifdef WRITE_SOCKET//  ...... use socket to transport data
    cout<<"sending this event via socket ...\n";
    // tell the clients to start
    EEmcMCData   data;
    const int mx=1<<14;
    char hitBuf[mx];
    int nh  = data.decode(emc_hit);
    cerr << "actual hits " << nh << endl;
    int nbw = ev->write(hitBuf,mx);
    int ret=s0->SendRaw(hitBuf,nbw);
    cout<<ret<<" char sent\n";
    if(ret!=nbw) {
      cerr<<"socekt Error1 "<<ret<<"  "<<nbw<<endl;
    }
#endif

#ifdef WRITE_FILE    //  ......  write events to bin file
    static FILE *fd=0;
    if(fd==0) {fd=fopen("data.bin","w"); assert(fd);}
    EEmcMCData   data;
    const int mx=1<<14;
    char hitBuf[mx];
    int nh  = data.decode(emc_hit);
    cerr << "actual hits " << nh << endl;
    int nbw = data->write(hitBuf,mx);
    char *cnbw=&nbw;
    int j;
    for(j=0;j<sizeof(int);j++) fputc(cnbw[j],fd);
    for(j=0;j<nbw;j++) fputc(hitBuf[j],fd);
#endif    

    // ..............   do sth with data locally
    EEuse1 jan(emc_hit);
    jan.work();


  }
}