来自的TCP示例中的参数列表后缺少未捕获的SyntaxError:)https://www.w3.org/TR/tcp-



我无法理解这一点,可能是因为JS对我来说相当陌生。然而,我相信这对有更多JS经验的人来说是微不足道的。

https://www.w3.org/TR/tcp-udp-sockets/有一个JS中TCP套接字的示例:

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);
);

当我进行这个狙击时,我得到了一个";未捕获的语法错误:缺少(在参数列表"之后;每次出现";e=>console.error("发送错误:",e(&";。我确信有些话不知怎么就漏了。有人能帮我吗?

您的问题是,对于mySocket.writeable.write().thenmySocket.opened.thenmySocket.closed.then的调用,在e => console.error("Sending error: ", e)e =>console.error("TCP connection setup failed due to error: ", e)e => console.error("TCP socket closed due to error: ", e)函数参数之后有一个分号。

相关内容

最新更新