Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
335 views
in Technique[技术] by (71.8m points)

javascript - Uncaught SyntaxError: missing ) after argument list in TCP example from https://www.w3.org/TR/tcp-udp-sockets/

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your issue is that there is a semicolon after the e => console.error("Sending error: ", e), e =>console.error("TCP connection setup failed due to error: ", e) and e => console.error("TCP socket closed due to error: ", e) function parameters for the calls to mySocket.writeable.write().then, mySocket.opened.then and mySocket.closed.then.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...