1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Allow tcp request node to accept msg.host and msg.port as inputs

Overrides only allowed if edit setting left blank.
This commit is contained in:
Dave C-J 2014-11-06 10:21:14 +00:00
parent 266a644ca6
commit 9c92eeb9f5
2 changed files with 20 additions and 12 deletions

View File

@ -213,7 +213,6 @@
else {
$("#fin-tip2").hide();
}
};
updateOptions();
$("#node-input-beserver").change(updateOptions);
@ -226,7 +225,7 @@
<div class="form-row">
<label for="node-input-server"><i class="fa fa-globe"></i> Server</label>
<input type="text" id="node-input-server" placeholder="ip.address" style="width:50%">
&nbsp;port <input type="text" id="node-input-port" style="width:50px">
&nbsp;port <input type="text" id="node-input-port" placeholder="port" style="width:50px">
</div>
<div class="form-row">
<label for="node-input-out"><i class="fa fa-sign-out"></i> Return</label>
@ -243,7 +242,8 @@
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-tips"><b>Tip:</b> outputs a binary <b>Buffer</b>, so you may want to .toString() it.</div>
<div class="form-tips"><b>Tip:</b> Outputs a binary <b>Buffer</b>, so you may want to .toString() it.</br/>
<b>Tip:</b> Leave host and port blank if you want to overide with msg.host and msg.port properties.</div>
<script>
var previous = null;
$("#node-input-out").on('focus', function () { previous = this.value; }).change(function() {
@ -273,6 +273,7 @@
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 and port blank you must set them by using the <b>msg.host</b> and <b>msg.port</b> properties.</p>
</script>
<script type="text/javascript">
@ -280,8 +281,8 @@
category: 'function',
color:"Silver",
defaults: {
server: {value:"",required:true},
port: {value:"",required:true,validate:RED.validators.number()},
server: {value:""},
port: {value:"",validate:RED.validators.regex(/^(\d*|)$/)},
out: {value:"time",required:true},
splitc: {value:"0",required:true},
name: {value:""}

View File

@ -377,12 +377,19 @@ module.exports = function(RED) {
client = net.Socket();
client.setTimeout(socketTimeout);
node.status({});
client.connect(node.port, node.server, function() {
var host = node.server || msg.host;
var port = node.port || msg.port;
if (host && port) {
client.connect(port, host, function() {
//node.log('client connected');
node.status({fill:"green",shape:"dot",text:"connected"});
node.connected = true;
client.write(msg.payload);
});
}
else {
node.warn("Host and/or port not set");
}
client.on('data', function(data) {
//node.log("data:"+ data.length+":"+ data);
@ -458,7 +465,7 @@ module.exports = function(RED) {
if (client) {
client.end();
setTimeout(function() {
client.connect(node.port, node.server, function() {
client.connect(port, host, function() {
//node.log('client connected');
node.connected = true;
client.write(msg.payload);