I'm new to NodeJS. The existing net.socket pipe need to filter by condition to not to connect to "con2", my existing code as follow.
I found Transform and PipeLine methods and, so far I tried, the sample code not working for my scenario yet.
The condition is in "con1" read stream data have some keyword. e.g. "Output" Then, not to connect or transform data as empty to "con2". So that, "con2" not to process.
Start.js
import Proxy from "./Proxy.js";
const proxy = Proxy();
proxy.listen('4000');
Proxy.js
import net from "net";
export default () =>
net.createServer((con1) => {
const con2 = net.connect(
'1234',
'127.0.0.1'
);
con1.pipe(con2).pipe(con1);
con2.on("data", async (data) => {
try {
console.log("sent from con2:", data);
}
}
}
con1.on("data", async (data) => {
try {
console.log("sent from con1:", data);
}
}
}
Please help advise. Thanks a lot in advance.