really close tcp node connection right away (if told to)

rather than wait then close
This commit is contained in:
Dave Conway-Jones 2017-03-06 19:05:16 +00:00
parent 99b8f16d88
commit 59da705b8f
2 changed files with 17 additions and 4 deletions

View File

@ -58,6 +58,8 @@
<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,
or accept incoming connections.</p>
<p><b>Note: </b>On some systems you may need root or administrator access
to access ports below 1024.</p>
</script>
<script type="text/javascript">
@ -149,12 +151,14 @@
<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,
accept incoming connections, or reply to messages received from a TCP In node.</p>
<p>Only <code>msg.payload</code> is sent.</p>
<p>Only the <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>
<p><b>Note: </b>On some systems you may need root or administrator access
to access ports below 1024.</p>
</script>
<script type="text/javascript">
@ -234,6 +238,7 @@
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 <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>
<p><b>Note: </b>Setting a timeout of 0 mS will return immediately and close the connection, without waiting for any reply.</p>
</script>
<script type="text/javascript">

View File

@ -446,6 +446,11 @@ module.exports = function(RED) {
if (clients[connection_id] && clients[connection_id].client) {
clients[connection_id].connected = true;
clients[connection_id].client.write(clients[connection_id].msg.payload);
if (node.out === "time" && node.splitc === 0) {
clients[connection_id].client.destroy();
clients[connection_id].connected = false;
node.status({});
}
}
});
}
@ -481,7 +486,8 @@ module.exports = function(RED) {
buf.copy(clients[connection_id].msg.payload,0,0,i+1);
node.send(clients[connection_id].msg);
if (clients[connection_id].client) {
node.status({}); clients[connection_id].client.destroy();
node.status({});
clients[connection_id].client.destroy();
delete clients[connection_id];
}
}
@ -501,7 +507,8 @@ module.exports = function(RED) {
buf.copy(clients[connection_id].msg.payload,0,0,i);
node.send(clients[connection_id].msg);
if (clients[connection_id].client) {
node.status({}); clients[connection_id].client.destroy();
node.status({});
clients[connection_id].client.destroy();
delete clients[connection_id];
}
i = 0;
@ -518,7 +525,8 @@ module.exports = function(RED) {
buf.copy(clients[connection_id].msg.payload,0,0,i);
node.send(clients[connection_id].msg);
if (clients[connection_id].client) {
node.status({}); clients[connection_id].client.destroy();
node.status({});
clients[connection_id].client.destroy();
delete clients[connection_id];
}
i = 0;