Network server and its CLient

Hello rooters

I’d like run a network servers and clients.
see files in attachment

In a root server session i’d like to run this lines

.L ServerRoot.C++
TH1S* histo1= new TH1S(“Histo1”,“histo1”,10,0,10);
TH1S* histo2= new TH1S(“Histo2”,"histo2 ",10,0,10);
for (int i = 0;i<10;i++){histo1 ->Fill(i,i);histo2 ->Fill(i,10-i);}

ServerRoot* serv1 = new ServerRoot();
ServerRoot* serv2 = new ServerRoot();

serv1 ->StartGNetServer();
serv2 ->StartGNetServer();

serv1 ->SetSpectra(histo1);
serv2 ->SetSpectra(histo2);

In other root client session i 'd like run

.L ClientRoot.C++

ClientRoot* client1 =new ClientRoot(“localhost”);
ClientRoot* client2 =new ClientRoot(“localhost”);


TH1* histo1= client1->GetSpectrum();
TH1* histo2= client1->GetSpectrum();

histo1 -> Draw();
histo2 -> Draw();

So, sometime it’s ok
sometime client is hang and server is with 100% cpu consumption
and sometime client or client crash

why theses different behaviours?

Thank for your help.

ClientRoot.C (4.91 KB)
ServerRoot.C (5.76 KB)


Is there anybody has tested my exemple??


Fons will process your problem



after looking at the ServerRoot.C is looks like you don’t need the read thread as you could do it all with just a single TMonitor (see example $ROOTSYS/tutorials/net/hserv.C). And if you want to use a reader thread you won’t need a TMonitor, just do socket->Recv(). I think the random behaviour is due to the fact that TMonitor is not thread save and that you have tow threads calling it without mutex.

Cheers, Fons.

Thanks to have seen my problem

Excuse-me to not understand
"TMonitor is not thread save"
and if this is a problem, how to correct it?

Second point ,you said "two threads calling it without mutex."
Have you some where a example using , thread, mutex and TServerSocket?

Thanks for your help

Hi Luc,

just look at hserv.C, I think you can make you code without thread, but just a TMonitor (which is a select) on the multiple sockets. If you want a thread you won’t need a TMonitor, just call sock->Recv() and wait till you get something.

Cheers, Fons.

You don’t need Tmonitor even you have multiple clients??


not if you have one thread per client.

Cheers, Fons.