Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TCPget can now handle concurrent sessions #1042

Merged
merged 6 commits into from Nov 11, 2016
Merged

Conversation

natcl
Copy link
Contributor

@natcl natcl commented Nov 9, 2016

The TCPget (TCP request) node wasn't able to handle multiple connections at the same time. This fixes the issue by storing each client instance in an object based on the ip+port as the key.

Here's a test flow that can show the behavior:

[{"id":"52c260ec.62ee68","type":"tcp request","z":"2decd90d.7e3056","server":"","port":"","out":"time","splitc":"20","name":"","x":730,"y":100,"wires":[["4fead340.86692c"]]},{"id":"adbc7290.16b538","type":"function","z":"2decd90d.7e3056","name":"","func":"var hosts = [\n    {host: \"127.0.0.1\", port: 5000, payload: \"ping1\", topic: \"topic1\"},\n    {host: \"127.0.0.1\", port: 5001, payload: \"ping2\", topic: \"topic2\"},\n    {host: \"127.0.0.1\", port: 5002, payload: \"ping3\", topic: \"topic3\"},\n    {host: \"127.0.0.1\", port: 5003, payload: \"ping4\", topic: \"topic4\"}\n    ];\n    \nfor (var h of hosts) {\n  node.send({\n        host: h.host,\n        port: h.port,\n        payload: h.payload, \n        topic: h.topic\n      \n  });  \n}\n","outputs":1,"noerr":0,"x":350,"y":100,"wires":[["94ebf65.95ab508"]]},{"id":"d2fae9c9.06d4d8","type":"debug","z":"2decd90d.7e3056","name":"","active":true,"console":"false","complete":"true","x":1090,"y":100,"wires":[]},{"id":"7ebe5f25.4ae2b","type":"inject","z":"2decd90d.7e3056","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":140,"y":100,"wires":[["adbc7290.16b538"]]},{"id":"c2059a60.26365","type":"tcp in","z":"2decd90d.7e3056","name":"","server":"server","host":"","port":"5000","datamode":"stream","datatype":"buffer","newline":"","topic":"","base64":false,"x":120,"y":300,"wires":[["8461edb3.de6278","b3ed0e21.08141"]]},{"id":"18bc4526.edc233","type":"tcp in","z":"2decd90d.7e3056","name":"","server":"server","host":"","port":"5001","datamode":"stream","datatype":"buffer","newline":"","topic":"","base64":false,"x":120,"y":340,"wires":[["5ce9b58e.14774c"]]},{"id":"471893f6.21e5bc","type":"tcp in","z":"2decd90d.7e3056","name":"","server":"server","host":"","port":"5002","datamode":"stream","datatype":"buffer","newline":"","topic":"","base64":false,"x":120,"y":380,"wires":[["16c56ab4.26f34d"]]},{"id":"5d96f7a8.0dc13","type":"tcp in","z":"2decd90d.7e3056","name":"","server":"server","host":"","port":"5003","datamode":"stream","datatype":"buffer","newline":"","topic":"","base64":false,"x":120,"y":420,"wires":[["82f56196.3a345","63c97e33.de09d"]]},{"id":"10550fc2.d22e48","type":"tcp out","z":"2decd90d.7e3056","host":"","port":"","beserver":"reply","base64":false,"end":false,"name":"","x":550,"y":300,"wires":[]},{"id":"7f2e04c3.4427a4","type":"tcp out","z":"2decd90d.7e3056","host":"","port":"","beserver":"reply","base64":false,"end":false,"name":"","x":550,"y":340,"wires":[]},{"id":"9181b21e.fb98f","type":"tcp out","z":"2decd90d.7e3056","host":"","port":"","beserver":"reply","base64":false,"end":false,"name":"","x":550,"y":380,"wires":[]},{"id":"5d35dc2.76cf224","type":"tcp out","z":"2decd90d.7e3056","host":"","port":"","beserver":"reply","base64":false,"end":false,"name":"","x":550,"y":420,"wires":[]},{"id":"8461edb3.de6278","type":"template","z":"2decd90d.7e3056","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload}} 5000","x":330,"y":300,"wires":[["10550fc2.d22e48"]]},{"id":"5ce9b58e.14774c","type":"template","z":"2decd90d.7e3056","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload}} 5001","x":330,"y":340,"wires":[["7f2e04c3.4427a4"]]},{"id":"16c56ab4.26f34d","type":"template","z":"2decd90d.7e3056","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload}} 5002","x":330,"y":380,"wires":[["9181b21e.fb98f"]]},{"id":"82f56196.3a345","type":"template","z":"2decd90d.7e3056","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload}} 5003","x":330,"y":420,"wires":[["5d35dc2.76cf224"]]},{"id":"94ebf65.95ab508","type":"delay","z":"2decd90d.7e3056","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":550,"y":100,"wires":[["52c260ec.62ee68"]]},{"id":"b9d689a9.3b0c6","type":"function","z":"2decd90d.7e3056","name":"","func":"var hosts = [\n    {host: \"127.0.0.1\", port: 5000, payload: \"ping1\", topic: \"topic1\"},\n    {host: \"127.0.0.1\", port: 5001, payload: \"ping2\", topic: \"topic2\"},\n    {host: \"127.0.0.1\", port: 5002, payload: \"ping3\", topic: \"topic3\"},\n    {host: \"127.0.0.1\", port: 5003, payload: \"ping4\", topic: \"topic4\"}\n    ];\n    \nfor (var h of hosts) {\n  node.send({\n        host: h.host,\n        port: h.port,\n        payload: h.payload, \n        topic: h.topic\n      \n  });  \n}\n","outputs":1,"noerr":0,"x":350,"y":200,"wires":[["52c260ec.62ee68"]]},{"id":"dc4ee9ce.6a93d8","type":"inject","z":"2decd90d.7e3056","name":"","topic":"Hello","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":160,"y":200,"wires":[["b9d689a9.3b0c6"]]},{"id":"dd65cb7.964ec38","type":"comment","z":"2decd90d.7e3056","name":"Works","info":"","x":110,"y":60,"wires":[]},{"id":"86f78caa.1a3a","type":"comment","z":"2decd90d.7e3056","name":"Fails","info":"","x":110,"y":160,"wires":[]},{"id":"d729e8da.fcd188","type":"tcp request","z":"2decd90d.7e3056","server":"127.0.0.1","port":"5004","out":"sit","splitc":"0","name":"Keep Open","x":330,"y":660,"wires":[["4c7d9412.5f13dc"]]},{"id":"be3fc12f.4457d8","type":"tcp in","z":"2decd90d.7e3056","name":"","server":"server","host":"","port":"5004","datamode":"stream","datatype":"buffer","newline":"","topic":"","base64":false,"x":120,"y":600,"wires":[["e5b1e16.a2de1a","8bcbfde3.82929"]]},{"id":"e5b1e16.a2de1a","type":"template","z":"2decd90d.7e3056","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload}} 5004","x":450,"y":600,"wires":[["c9bdbeb8.06bca"]]},{"id":"c9bdbeb8.06bca","type":"tcp out","z":"2decd90d.7e3056","host":"","port":"","beserver":"reply","base64":false,"end":false,"name":"","x":630,"y":600,"wires":[]},{"id":"b844ac10.1458a8","type":"inject","z":"2decd90d.7e3056","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":140,"y":660,"wires":[["d729e8da.fcd188"]]},{"id":"4c7d9412.5f13dc","type":"debug","z":"2decd90d.7e3056","name":"","active":true,"console":"false","complete":"true","x":540,"y":660,"wires":[]},{"id":"8bcbfde3.82929","type":"delay","z":"2decd90d.7e3056","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":280,"y":560,"wires":[["e5b1e16.a2de1a"]]},{"id":"b3ed0e21.08141","type":"delay","z":"2decd90d.7e3056","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":320,"y":260,"wires":[["10550fc2.d22e48"]]},{"id":"63c97e33.de09d","type":"delay","z":"2decd90d.7e3056","name":"","pauseType":"delay","timeout":"8","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":320,"y":460,"wires":[["5d35dc2.76cf224"]]},{"id":"4fead340.86692c","type":"function","z":"2decd90d.7e3056","name":"","func":"msg.topic = msg.topic + '/hello';\nreturn msg;","outputs":1,"noerr":0,"x":930,"y":100,"wires":[["d2fae9c9.06d4d8"]]}]

@coveralls
Copy link

coveralls commented Nov 9, 2016

Coverage Status

Coverage decreased (-0.06%) to 88.083% when pulling d56fce3 on natcl:tcpgetfix into 0a5a42b on node-red:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 87.972% when pulling 385d9f1 on natcl:tcpgetfix into 0a5a42b on node-red:master.

@coveralls
Copy link

coveralls commented Nov 10, 2016

Coverage Status

Coverage decreased (-0.06%) to 88.083% when pulling 385d9f1 on natcl:tcpgetfix into 0a5a42b on node-red:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 87.972% when pulling 9682041 on natcl:tcpgetfix into 0a5a42b on node-red:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 87.972% when pulling 9682041 on natcl:tcpgetfix into 0a5a42b on node-red:master.

@coveralls
Copy link

coveralls commented Nov 10, 2016

Coverage Status

Coverage decreased (-0.06%) to 88.083% when pulling 9682041 on natcl:tcpgetfix into 0a5a42b on node-red:master.

@coveralls
Copy link

coveralls commented Nov 10, 2016

Coverage Status

Coverage decreased (-0.06%) to 88.083% when pulling 869ae01 on natcl:tcpgetfix into 0a5a42b on node-red:master.

Copy link
Member

@dceejay dceejay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is var cid scoped correctly ? - you also fairly mix node.connection_id and cid quite a bit ... can their use be more consistent.

@natcl
Copy link
Contributor Author

natcl commented Nov 10, 2016

Just updated with connection_id scoped more logically, it's local to on("input") now.

@coveralls
Copy link

coveralls commented Nov 10, 2016

Coverage Status

Coverage decreased (-0.06%) to 88.083% when pulling d853eca on natcl:tcpgetfix into 0a5a42b on node-red:master.

@dceejay dceejay merged commit 7ef1537 into node-red:master Nov 11, 2016
@dceejay
Copy link
Member

dceejay commented Nov 11, 2016

Nice one @natcl . Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants