This script shows how to make a simple iterative server that can receive TMemFile from multiple clients and merge them into a single file without block.
Note: This server assumes that the client will reset the histogram after each upload to simplify the merging.
This server 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 fastMergerServer.C
- Execute in the second and third windows: .x treeClient.C
void fastMergeServer(bool cache = false) {
return;
}
merger.SetPrintLevel(0);
enum StatusKind {
kStartConnection = 0,
kProtocol = 1,
kProtocolVersion = 1
};
while (1) {
if (clientCount > 100) {
printf("only accept 100 clients connections\n");
} else {
client->
Send(clientCount, kStartConnection);
client->
Send(kProtocolVersion, kProtocol);
++clientCount;
printf("Accept %d connections\n",clientCount);
}
continue;
}
if (mess==0) {
Error(
"fastMergeServer",
"The client did not send a message\n");
char str[64];
printf("Client %d: %s\n", clientCount, str);
printf(
"Client %d: bytes recv = %d, bytes sent = %d\n", clientCount, s->
GetBytesRecv(),
--clientCount;
if (mon->
GetActive() == 0 || clientCount == 0) {
printf("No more active clients... stopping\n");
break;
}
Info(
"fastMergeServer",
"Receive input from client %d for %s",clientId,filename.
Data());
delete transient;
merger.OutputFile(filename,"UPDATE");
merger.AddAdoptFile(transient);
transient = 0;
} else {
printf("*** Unexpected message ***\n");
}
delete mess;
}
}
- Author
- Fons Rademakers
Definition in file fastMergeServer.C.