The official tcp request node of Node-RED has some problems:
If a fixed timeout is set, it will always wait for the same time (although the impact is not great); if a fixed data length is set, if the other party does not return the content, the connection will hang there.
Therefore, a maximum waiting length of x is needed. Within y seconds, if there is no return, a timeout will be reported. However, if x length is returned within y seconds, the waiting will end immediately and the content will be returned.
In addition, the splitc variable has two different meanings in the time and count modes respectively. I think they should be separated.
Different from the official tcp request node, tcp request2 has the following modifications:
- Retain the original logic based on time, characters, and length.
- socketTimeout can be set through the overtime parameter in the settings interface.
- server and port can be set through msg, global, flow, and env.
- The buffer length can be set manually under non-length-based TCP request methods.
- Run
npm start
to start a demo flow with a tcp request node and a tcp in node. The tcp request node sends a request to the tcp in node, which returns a response. - The example is under
examples/tcp_request2_demo.json
. You can import it into your Node-RED instance.
With test tcp server like this:
- Install dependencies using
pnpm install -r
- To run tests, execute
pnpm test
. To add tests, create a files<description>.spec.js
with a mocha test specification. - Using changesets: Before committing a change that should be visible on the changelog run
npx changeset
and input the corresponding information into the wizard. Then add the created file in the.changeset
folder to the commit. - Publishing: If not done yet, login to npm using
npm login --registry=https://registry.npmjs.org --scope=@mingxingzhang
. Then runnpx changeset version
to create a new version number, update package.json and the CHANGELOG.md files. Commit these changes with messageRelease VX.Y.Z
. Then runnpx changeset publish
npm publish --access public
to publish to npm. Now rungit push --follow-tags
to push the version tag created by changeset. - Validate the package(just once):
npm run validate
.