I cannot figure this out, probably because JS is rather new to me. However I am sure this is trivial for someone w/ more experience in JS.
https://www.w3.org/TR/tcp-udp-sockets/ has an example for TCP sockets in JS:
navigator.tcpPermission.requestPermission({remoteAddress:"127.0.0.1", remotePort:6789}).then(
() => {
// Permission was granted
// Create a new TCP client socket and connect to remote host
var mySocket = new TCPSocket("127.0.0.1", 6789);
// Send data to server
mySocket.writeable.write("Hello World").then(
() => {
// Data sent sucessfully, wait for response
console.log("Data has been sent to server");
mySocket.readable.getReader().read().then(
({ value, done }) => {
if (!done) {
// Response received, log it:
console.log("Data received from server:" + value);
}
// Close the TCP connection
mySocket.close();
}
);
},
e => console.error("Sending error: ", e);
);
// Signal that we won't be writing any more and can close the write half of the connection.
mySocket.halfClose();
// Log result of TCP connection attempt.
mySocket.opened.then(
() => {
console.log("TCP connection established sucessfully");
},
e =>console.error("TCP connection setup failed due to error: ", e);
);
// Handle TCP connection closed, either as a result of the webapp
// calling mySocket.close() or the other side closed the TCP
// connection or an error causing the TCP connection to be closed.
mySocket.closed.then(
() => {
console.log("TCP socket has been cleanly closed");
},
e => console.error("TCP socket closed due to error: ", e);
);
},
e => console.error("Connection to 127.0.0.1 on port 6789 was denied
due to error: ", e);
);
when I run this snipped I get an "Uncaught SyntaxError: missing ) after argument list" on every occurence of " e => console.error("Sending error: ", e);". I am sure some quotes run off, somehow. Can anyone help me out please?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…