This script shows how to make a simple iterative server that can accept connections while handling currently open connections.
Compare this script to hserv.C that blocks on accept. In this script a server socket is created and added to a monitor. A monitor object is used to monitor connection requests on the server socket. After accepting the connection the new socket is added to the monitor and immediately ready for use. Once two connections are accepted the server socket is removed from the monitor and closed. The monitor continues monitoring the sockets.
To run this demo do the following:
- Open three windows
- Start ROOT in all three windows
- Execute in the first window: .x hserv2.C
- Execute in the second and third windows: .x hclient.C
{
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);
while (1) {
} else
printf(
"only accept two client connections\n");
}
continue;
}
char str[64];
mess->ReadString(str, 64);
printf(
"Client %d: %s\n", s==
s0 ? 0 : 1, str);
if (
mon->GetActive() == 0) {
printf(
"No more active clients... stopping\n");
break;
}
else
}
} else {
printf(
"*** Unexpected message ***\n");
}
}
printf(
"Client 0: bytes recv = %d, bytes sent = %d\n",
s0->GetBytesRecv(),
printf(
"Client 1: bytes recv = %d, bytes sent = %d\n",
s1->GetBytesRecv(),
}
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
TH1 is the base class of all histogram classes in ROOT.
The most important graphics class in the ROOT system.
virtual Int_t Recv(TMessage *&mess)
Receive a TMessage object.
TClass * IsA() const override
- Author
- Fons Rademakers
Definition in file hserv2.C.