RanvierMUD / websocket-networking

1 stars 8 forks source link

Websocket connect error #4

Closed SupZ6 closed 3 years ago

SupZ6 commented 5 years ago

Describe the bug The first connection is OK, but it will be wrong if you refresh the page and connect again.

Error logs

2019-08-22T10:54:42.281Z - info: START - Starting server 2019-08-22T10:54:42.283Z - info: Telnet server started on port: 4000... 2019-08-22T10:54:42.283Z - info: Websocket server started on port: 4001... 2019-08-22T10:54:46.652Z - info: User connected via websocket... events.js:180 throw er; // Unhandled 'error' event ^

Error: read ECONNRESET at TCP.onStreamRead (internal/stream_base_commons.js:183:27) Emitted 'error' event at: at WebSocket.finalize (/Users/pc/Documents/muddev/ranviermud/bundles/websocket-networking/node_modules/ws/lib/WebSocket.js:182:41) at Socket.emit (events.js:203:13) at emitErrorNT (internal/streams/destroy.js:91:8) at emitErrorAndCloseNT (internal/streams/destroy.js:59:3) at processTicksAndRejections (internal/process/task_queues.js:77:11) { errno: 'ECONNRESET', code: 'ECONNRESET', syscall: 'read' }

Environment (please complete the following information):

Additional context

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>WebSocket Connect</title>
</head>

<body>
    <script type="text/javascript">
        var sock = null;
        //WebSocket URI
        var wsuri = "ws://127.0.0.1:4001/";
        window.onload = function () {
            console.log("onload");
            sock = new WebSocket(wsuri);
            sock.onopen = function () {
                //Success
                console.log("connected to " + wsuri);
            }
            sock.onclose = function (e) {
                console.log("connection closed (" + e.code + ")");
            }
            sock.onmessage = function (e) {
                //Send messenger
                console.log("message received: " + e.data);
            }
        };

        function send() {
            var msg = document.getElementById('message').value;
            sock.send(msg);
        };

    </script>

    Message: <input id="message" type="text" value="">
    <button onclick="send();">Send Message</button>
</body>

</html>
stennie commented 3 years ago

This appears to be the same issue as #1. Closing as a duplicate.