Your second code block looks more appropriate. We can't really tell if your NAT and port forwarding is set up correctly, but if it is, then you should be able to make a socket.io connection from a web page with this:
<script src="/socket.io/socket.io.js"></script>
<script>
const socket = io("http://myWANIP:3400", {transports: ["webSocket"]});
</script>
And, when that connection occurs, you should see the results of console.log('connection');
in the server logs.
Another way to verify that your NAT and port forwarding is working correctly is to add this to your server:
app.get("/", (req, res) => {
console.log("got web page request");
res.send("hello");
});
Then, when you got to http://myWANIP:3400
, in the browser, you should get a log on your server and a response page back that says "hello".
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…