Skip to content

Commit 75bde98

Browse files
Mary ellen KerrGitHub Enterprise
authored andcommitted
Task/ric 1076 add the tcp range counter client to the code rt samples (#63)
* A new Node.js Express Client sample is provided that sends events to the TcpRangeCounter sample. * Removed some dependencies, removed HCL image, moved some styling to style.css, put under client-ui folder. * Updates to the TcpRangeCounter and TcpRangeCounter_Client README.md files. * The index.ejs prompts the user for hostname & port which is used by the index.js file to remove the hardcoding of hostname & port. The README.md was updated.
1 parent d671234 commit 75bde98

5 files changed

Lines changed: 43 additions & 33 deletions

File tree

art-samples/TcpRangeCounter/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ where <arg> is one of:
2525
-min <int> : Set min of range
2626
-delta <int> : Set delta (positive to count up, negative to count down)
2727
-resume : Resume counting
28-
```
28+
```
29+
30+
Alternatively, the sample includes a web application which also uses the [rt-test-probe] utility for making TCP requests. The link to the README for using this web application is [TcpRangeCounter_Client README](client-ui\README.md).
Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
# TcpRangeCounter Client
22

3-
This Node.js Express sample client works with the TcpRangeCounter sample by sending events to the TcpRangeCounter sample. The TcpRangeCounter sample implements a counter that starts at a min value and increments until it reaches a max value. It embeds a TCP server which allows it to be dynamically configured by means of sending TCP requests. These requests corresponds to the events of the Events protocol:
3+
This TcpRangeCounter_Client works with the TcpRangeCounter sample by sending the following events to the TcpRangeCounter sample.
4+
- setMin: Sets the min value of the range (default 0).
5+
- setMax: Sets the max value of the range (default 10).
6+
- setDelta: Sets the delta by which the counter increments in each step (default 1; Use a negative value to count down instead of up).
7+
- resumeCounting: Resume the counter when it has stopped.
8+
9+
The instructions to run this TcpRangeCounter_Client are as follows:
10+
- Build and start the TcpRangeCounter sample by following the directions in its README file.
11+
- Start this client sample by entering 'npm install' and then 'npm start' in a terminal session. The TcpRangeCounter_Client listens on port 3000.
12+
- Invoke the TcpRangeCounter_Client in a web browser at http://localhost:3000/.
13+
- Select the Event type and enter its Argument to send the event to the TcpRangeCounter sample.
14+
- Enter the Hostname or IP address that the TcpRangeCounter sample is running on.
15+
- Enter the Port that the TcpRangeCounter sample is listening on.
16+
- Click the Submit button.
417

5-
* setMin: Sets the min value of the range (default 0).
6-
7-
* setMax: Sets the max value of the range (default 10).
8-
9-
* setDelta: Sets the delta by which the counter increments in each step (default 1; Use a negative value to count down instead of up).
10-
11-
* resumeCounting: Resume the counter when it has stopped.
12-
13-
The following are instructions to run this sample client.
14-
15-
* Build and start the TcpRangeCounter sample by following the directions in its README file.
16-
17-
* Start this sample client by entering 'npm install' and then 'npm start' in a terminal session. The client listens on port 3000.
18-
19-
* Invoke the sample client in a web browser at http://localhost:3000/.

art-samples/TcpRangeCounter/client-ui/public/stylesheets/style.css

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,11 @@ a {
2929
}
3030

3131
hr.lightgrey {
32-
border: 3px solid lightgrey;
32+
border: 1px solid lightgrey;
3333
}
3434

35-
hr.lightgreen {
36-
border: 3px solid #e6fff7;
37-
}
35+
36+
3837

3938

4039

art-samples/TcpRangeCounter/client-ui/routes/index.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
var express = require('express');
22
var router = express.Router();
3-
const testProbe = require ('rt-test-probe')('localhost', 12345);
4-
3+
54
function sendEvent(data, fn) {
65

76
console.log("Entered the sendEvent function");
87

98
var eventType = data.eventType;
109
var arg = data.arg;
10+
var hostname = data.hostname;
11+
var port = data.port;
1112

1213
console.log("Event Type = " + eventType);
1314
console.log("Argument = " + arg);
15+
console.log("Hostname = " + hostname);
16+
console.log("Port = " + port);
17+
18+
const testProbe = require ('rt-test-probe')(hostname, port);
1419

1520
let success = false;
1621

@@ -49,8 +54,8 @@ router.post('/sendEvent', function(req, res) {
4954
console.log("JSON.stringify(req.body) = " + JSON.stringify(req.body));
5055
if (req.body != undefined) {
5156
sendEvent(req.body, function(err, data)
52-
{ res.render('status', { title: 'Range Counter Client', data: data }); });
53-
}
54-
});
57+
{ res.render('status', { title: 'Range Counter Client', data: data }); });
58+
}
59+
});
5560

5661
module.exports = router;

art-samples/TcpRangeCounter/client-ui/views/index.ejs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,27 @@
55
<link rel="stylesheet" href="stylesheets/style.css"/>
66
</head>
77
<body>
8-
<hr class="lightgrey"></hr>
8+
<hr class = "lightgrey" />
99
<h1>TcpRangeCounter Client</h1>
1010
<section id="inputSection">
1111
<form method=post action=sendEvent>
12-
<H3>Select the Event Type</H3>
12+
</br></br>
13+
<label>Select the Event Type:</label>
1314
<select id=selection name = "eventType">
1415
<option value="max">max</option>
1516
<option value="min">min</option>
1617
<option value="delta">delta</option>
1718
<option value="resume">resume</option>
18-
</select>
19-
<H3>Enter the Argument associated with the selected Event</H3>
20-
<input id=arg type="number" name="arg" size="10" required/>
21-
<br><br>
22-
<input type=submit value='submit' name=submit>
19+
</select></br></br>
20+
<label>Enter the Argument associated with the selected Event:</label>
21+
<input id=arg type="number" name="arg" size="10" required/></br></br>
22+
<hr class = "lightgrey" />
23+
<label>Enter the Hostname that the RangeCounter is running on:</label>
24+
<input id=hostname type="text" name="hostname" size="20" value = "127.0.0.1" required/></br></br>
25+
<label>Enter the Port that the RangeCounter is listening on:</label>
26+
<input id=port type="number" name="port" size="10" value = "12345" required/></br></br>
27+
<hr class = "lightgrey" />
28+
<input type=submit value='submit' name=submit>
2329
</form>
2430
<ul>
2531
<li>This sample implements a counter that starts at a min value and increments until it reaches a max value.</li>

0 commit comments

Comments
 (0)