Skip to content

Commit

Permalink
tcp node add reply (to all) capability
Browse files Browse the repository at this point in the history
if no _session present.
  • Loading branch information
Dave Conway-Jones committed Feb 12, 2016
1 parent d69bcad commit 7f6915e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
18 changes: 10 additions & 8 deletions nodes/core/io/31-tcpin.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
</script>

<script type="text/x-red" data-help-name="tcp in">
<p>Provides a choice of tcp inputs. Can either connect to a remote tcp port,
<p>Provides a choice of TCP inputs. Can either connect to a remote TCP port,
or accept incoming connections.</p>
</script>

Expand Down Expand Up @@ -147,12 +147,14 @@
</script>

<script type="text/x-red" data-help-name="tcp out">
<p>Provides a choice of tcp outputs. Can either connect to a remote tcp port,
<p>Provides a choice of TCP outputs. Can either connect to a remote TCP port,
accept incoming connections, or reply to messages received from a TCP In node.</p>
<p>Only <b>msg.payload</b> is sent.</p>
<p>If <b>msg.payload</b> is a string containing a Base64 encoding of binary
<p>Only <code>msg.payload</code> is sent.</p>
<p>If <code>msg.payload</code> is a string containing a Base64 encoding of binary
data, the Base64 decoding option will cause it to be converted back to binary
before being sent.</p>
<p>If <code>msg._session</code> is not present the payload is
sent to <b>all</b> connected clients.</p>
</script>

<script type="text/javascript">
Expand Down Expand Up @@ -247,12 +249,12 @@
</script>

<script type="text/x-red" data-help-name="tcp request">
<p>A simple TCP request node - sends the <b>msg.payload</b> to a server tcp port and expects a response.</p>
<p>Connects, sends the "request", reads the "response". It can either count a number of
<p>A simple TCP request node - sends the <code>msg.payload</code> to a server tcp port and expects a response.</p>
<p>Connects, sends the "request", and reads the "response". It can either count a number of
returned characters into a fixed buffer, match a specified character before returning,
wait a fixed timeout from first reply and then return, or just sit and wait for data.</p>
<p>The response will be output in <b>msg.payload</b> as a buffer, so you may want to .toString() it.</p>
<p>If you leave tcp host or port blank they must be set by using the <b>msg.host</b> and <b>msg.port</b> properties.</p>
<p>The response will be output in <code>msg.payload</code> as a buffer, so you may want to .toString() it.</p>
<p>If you leave tcp host or port blank they must be set by using the <code>msg.host</code> and <code>msg.port</code> properties.</p>
</script>

<script type="text/javascript">
Expand Down
11 changes: 11 additions & 0 deletions nodes/core/io/31-tcpin.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,17 @@ module.exports = function(RED) {
}
}
}
else {
for (var i in connectionPool) {
if (Buffer.isBuffer(msg.payload)) {
connectionPool[i].write(msg.payload);
} else if (typeof msg.payload === "string" && node.base64) {
connectionPool[i].write(new Buffer(msg.payload,'base64'));
} else {
connectionPool[i].write(new Buffer(""+msg.payload));
}
}
}
});
} else {
var connectedSockets = [];
Expand Down

0 comments on commit 7f6915e

Please sign in to comment.