ROOT
master
Reference Guide
Loading...
Searching...
No Matches
pserv.C
Go to the documentation of this file.
1
/// \file
2
/// \ingroup tutorial_net
3
/// Server program to test parallel sockets.
4
///
5
/// To run this demo do the following:
6
/// - Open two windows
7
/// - Start ROOT in all two windows
8
/// - Execute in the first window: .x pserv.C
9
/// - Execute in the second window: .x pclient.C
10
///
11
/// \macro_code
12
///
13
/// \author Fons Rademakers
14
15
void
pserv
()
16
{
17
// Open a parallel server socket looking for connections on a named
18
// service or on a specified port.
19
//TPServerSocket *ss = new TServerSocket("rootserv", kTRUE);
20
TPServerSocket
*
ss
=
new
TPServerSocket
(9090,
kTRUE
);
21
22
// Accept a connection and return a full-duplex communication socket.
23
TPSocket
*sock =
ss
->Accept();
24
delete
ss
;
25
26
int
niter
,
bsize
;
27
sock->
Recv
(
niter
,
bsize
);
28
29
printf
(
"Receive %d buffers of %d bytes over %d parallel sockets...\n"
,
30
niter
,
bsize
, sock->
GetSize
());
31
32
char
*buf =
new
char
[
bsize
];
33
34
// start timer
35
TStopwatch
timer
;
36
timer
.Start();
37
38
// accept data from client
39
for
(
int
i = 0; i <
niter
; i++) {
40
memset
(buf, 0,
bsize
);
41
int
ret
= sock->
RecvRaw
(buf,
bsize
);
42
if
(
ret
< 0) {
43
printf
(
"error receiving\n"
);
44
break
;
45
}
46
if
(buf[0] != 65) {
47
printf
(
"received data corrupted\n"
);
48
break
;
49
}
50
}
51
52
delete
sock;
53
delete
[] buf;
54
55
// stop timer and print results
56
timer
.Stop();
57
Double_t
rtime
=
timer
.RealTime();
58
Double_t
ctime
=
timer
.CpuTime();
59
60
printf
(
"%d bytes received in %f seconds\n"
,
niter
*
bsize
,
rtime
);
61
if
(
rtime
> 0)
printf
(
"%5.2f MB/s\n"
,
Double_t
(
niter
*
bsize
/1024/1024)/
rtime
);
62
}
Double_t
double Double_t
Definition
RtypesCore.h:59
kTRUE
constexpr Bool_t kTRUE
Definition
RtypesCore.h:93
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
ROOT::Detail::TRangeCast
Definition
TCollection.h:311
TPServerSocket
Definition
TPServerSocket.h:31
TPSocket
Definition
TPSocket.h:33
TPSocket::Recv
Int_t Recv(TMessage *&mess) override
Receive a TMessage object.
Definition
TPSocket.cxx:626
TPSocket::GetSize
Int_t GetSize() const
Definition
TPSocket.h:83
TPSocket::RecvRaw
Int_t RecvRaw(void *buffer, Int_t length, ESendRecvOptions opt=kDefault) override
Send a raw buffer of specified length.
Definition
TPSocket.cxx:679
TStopwatch
Stopwatch class.
Definition
TStopwatch.h:28
tutorials
legacy
net
pserv.C
ROOT master - Reference Guide Generated on Fri Jan 24 2025 04:37:20 (GVA Time) using Doxygen 1.10.0