Express-Ws closing connection closes unexpectedlyWhat is Node.js' Connect, Express and “middleware”?How to get the full url in Express?How to access the GET parameters after “?” in Express?Node js ECONNRESETSocket.IO removes all connections when browser is closedWhy do many websocket libraries implement their own application-level heartbeats?websocket ping with node jsexpress-ws route unable to connect on herokuSocket.io Java client automatically disconnects after a few secondsHow do you create SSL encrypted WebSockets from the express-ws middle ware using the 4.x project structure?

LED not blinking when using a transistor

What aircraft was used as Air Force One for the flight between Southampton and Shannon?

Is it possible to fly backward if you have really strong headwind?

How can I make 12 tone and atonal melodies sound interesting?

Ability To Change Root User Password (Vulnerability?)

What does the pair of vertical lines in empirical entropy formula mean?

Who won a Game of Bar Dice?

Why is Na5 not played in this line of the French Defense, Advance Variation?

Why am I getting a strange double quote (“) in Open Office instead of the ordinary one (")?

Java Servlet & JSP simple login

Separate SPI data

Why is long-term living in Almost-Earth causing severe health problems?

Why Does Mama Coco Look Old After Going to the Other World?

Confused with atmospheric pressure equals plastic balloon’s inner pressure

Should I refuse to be named as co-author of a low quality paper?

Translating “About that...”

How can I remove material from this wood beam?

Difference between prepositions in "...killed during/in the war"

Who is "He that flies" in Lord of the Rings?

Does putting salt first make it easier for attacker to bruteforce the hash?

Why do radiation hardened IC packages often have long leads?

Is Lambda Calculus purely syntactic?

Reference to understand the notation of orbital charts

What would be the way to say "just saying" in German? (Not the literal translation)



Express-Ws closing connection closes unexpectedly


What is Node.js' Connect, Express and “middleware”?How to get the full url in Express?How to access the GET parameters after “?” in Express?Node js ECONNRESETSocket.IO removes all connections when browser is closedWhy do many websocket libraries implement their own application-level heartbeats?websocket ping with node jsexpress-ws route unable to connect on herokuSocket.io Java client automatically disconnects after a few secondsHow do you create SSL encrypted WebSockets from the express-ws middle ware using the 4.x project structure?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am trying to use express-ws to enable websocket for express. I have two express servers and both uses ws. The code for setting up the ws is exactly the same for both servers (except the path names). One of the server is working as expected. The other one, closes as soon as a connection is established with exit code 1005. As far as I have researched, I have found 1005 to be described as a special error code to be returned in cases of unexpected disconnection. I have tried logging inside the ws route handler and, it prints nothing. On 'connection' handler is also not fired.



const expressWs = require('express-ws')(server, null wsOptions: clientTracking: true );
//<... HTTP route setup and middleware mounting >
server.ws('/',(sck, req)=> {
sck.on('connection', (s1) =>
console.dir(s1);
console.log('Connected')
);
let interval = setInterval(() =>
expressWs.getWss().clients.forEach(s =>
if(s.readyState === WS_CONSTANTS.Open)
s.ping(null, false, null);

);
, WS_HEARTBEAT_DELAY);
sck.on('close', (ev) =>
console.dir(ev);
clearInterval(interval);
);
//<... Other code for route handling >


As you can see, I implemented a 'heartbeat' technique for sending a ping to client to keep connection alive. As stated, it worked perfectly for only one of the server. I am very confused as to why 1005 is returned.



EDIT 1



Following this post here, I tried updating ws package for express-ws manually. This still did not solve the issue and the connection is still dropped with 1005 as reported earlier.










share|improve this question






























    0















    I am trying to use express-ws to enable websocket for express. I have two express servers and both uses ws. The code for setting up the ws is exactly the same for both servers (except the path names). One of the server is working as expected. The other one, closes as soon as a connection is established with exit code 1005. As far as I have researched, I have found 1005 to be described as a special error code to be returned in cases of unexpected disconnection. I have tried logging inside the ws route handler and, it prints nothing. On 'connection' handler is also not fired.



    const expressWs = require('express-ws')(server, null wsOptions: clientTracking: true );
    //<... HTTP route setup and middleware mounting >
    server.ws('/',(sck, req)=> {
    sck.on('connection', (s1) =>
    console.dir(s1);
    console.log('Connected')
    );
    let interval = setInterval(() =>
    expressWs.getWss().clients.forEach(s =>
    if(s.readyState === WS_CONSTANTS.Open)
    s.ping(null, false, null);

    );
    , WS_HEARTBEAT_DELAY);
    sck.on('close', (ev) =>
    console.dir(ev);
    clearInterval(interval);
    );
    //<... Other code for route handling >


    As you can see, I implemented a 'heartbeat' technique for sending a ping to client to keep connection alive. As stated, it worked perfectly for only one of the server. I am very confused as to why 1005 is returned.



    EDIT 1



    Following this post here, I tried updating ws package for express-ws manually. This still did not solve the issue and the connection is still dropped with 1005 as reported earlier.










    share|improve this question


























      0












      0








      0








      I am trying to use express-ws to enable websocket for express. I have two express servers and both uses ws. The code for setting up the ws is exactly the same for both servers (except the path names). One of the server is working as expected. The other one, closes as soon as a connection is established with exit code 1005. As far as I have researched, I have found 1005 to be described as a special error code to be returned in cases of unexpected disconnection. I have tried logging inside the ws route handler and, it prints nothing. On 'connection' handler is also not fired.



      const expressWs = require('express-ws')(server, null wsOptions: clientTracking: true );
      //<... HTTP route setup and middleware mounting >
      server.ws('/',(sck, req)=> {
      sck.on('connection', (s1) =>
      console.dir(s1);
      console.log('Connected')
      );
      let interval = setInterval(() =>
      expressWs.getWss().clients.forEach(s =>
      if(s.readyState === WS_CONSTANTS.Open)
      s.ping(null, false, null);

      );
      , WS_HEARTBEAT_DELAY);
      sck.on('close', (ev) =>
      console.dir(ev);
      clearInterval(interval);
      );
      //<... Other code for route handling >


      As you can see, I implemented a 'heartbeat' technique for sending a ping to client to keep connection alive. As stated, it worked perfectly for only one of the server. I am very confused as to why 1005 is returned.



      EDIT 1



      Following this post here, I tried updating ws package for express-ws manually. This still did not solve the issue and the connection is still dropped with 1005 as reported earlier.










      share|improve this question
















      I am trying to use express-ws to enable websocket for express. I have two express servers and both uses ws. The code for setting up the ws is exactly the same for both servers (except the path names). One of the server is working as expected. The other one, closes as soon as a connection is established with exit code 1005. As far as I have researched, I have found 1005 to be described as a special error code to be returned in cases of unexpected disconnection. I have tried logging inside the ws route handler and, it prints nothing. On 'connection' handler is also not fired.



      const expressWs = require('express-ws')(server, null wsOptions: clientTracking: true );
      //<... HTTP route setup and middleware mounting >
      server.ws('/',(sck, req)=> {
      sck.on('connection', (s1) =>
      console.dir(s1);
      console.log('Connected')
      );
      let interval = setInterval(() =>
      expressWs.getWss().clients.forEach(s =>
      if(s.readyState === WS_CONSTANTS.Open)
      s.ping(null, false, null);

      );
      , WS_HEARTBEAT_DELAY);
      sck.on('close', (ev) =>
      console.dir(ev);
      clearInterval(interval);
      );
      //<... Other code for route handling >


      As you can see, I implemented a 'heartbeat' technique for sending a ping to client to keep connection alive. As stated, it worked perfectly for only one of the server. I am very confused as to why 1005 is returned.



      EDIT 1



      Following this post here, I tried updating ws package for express-ws manually. This still did not solve the issue and the connection is still dropped with 1005 as reported earlier.







      node.js express ws






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 25 at 11:15







      Abrar Hossain

















      asked Mar 24 at 20:53









      Abrar HossainAbrar Hossain

      4133821




      4133821






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Okay I have finally found the error. In my code for the server, I had the following:



          server.get('*', async (req, res, nxt) => 
          nxt(new Error('Unsupported Method'));
          );


          I had this to prevent any get requests from being processed since, the API solely relies on post routes. I changed it to the following:



          server.get('*', async (req, res, nxt) => 
          nxt();
          );


          This solved the problem. IMHO, I think the ws 'upgrade' happens over GET and responding with an error to get requests was blocking any upgrade request. Also, I ensured that the other server had no such blocking and this is why I initially assumed that both the servers had the same setup and this was confusing me. Hope this was helpful.






          share|improve this answer

























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55328461%2fexpress-ws-closing-connection-closes-unexpectedly%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Okay I have finally found the error. In my code for the server, I had the following:



            server.get('*', async (req, res, nxt) => 
            nxt(new Error('Unsupported Method'));
            );


            I had this to prevent any get requests from being processed since, the API solely relies on post routes. I changed it to the following:



            server.get('*', async (req, res, nxt) => 
            nxt();
            );


            This solved the problem. IMHO, I think the ws 'upgrade' happens over GET and responding with an error to get requests was blocking any upgrade request. Also, I ensured that the other server had no such blocking and this is why I initially assumed that both the servers had the same setup and this was confusing me. Hope this was helpful.






            share|improve this answer





























              0














              Okay I have finally found the error. In my code for the server, I had the following:



              server.get('*', async (req, res, nxt) => 
              nxt(new Error('Unsupported Method'));
              );


              I had this to prevent any get requests from being processed since, the API solely relies on post routes. I changed it to the following:



              server.get('*', async (req, res, nxt) => 
              nxt();
              );


              This solved the problem. IMHO, I think the ws 'upgrade' happens over GET and responding with an error to get requests was blocking any upgrade request. Also, I ensured that the other server had no such blocking and this is why I initially assumed that both the servers had the same setup and this was confusing me. Hope this was helpful.






              share|improve this answer



























                0












                0








                0







                Okay I have finally found the error. In my code for the server, I had the following:



                server.get('*', async (req, res, nxt) => 
                nxt(new Error('Unsupported Method'));
                );


                I had this to prevent any get requests from being processed since, the API solely relies on post routes. I changed it to the following:



                server.get('*', async (req, res, nxt) => 
                nxt();
                );


                This solved the problem. IMHO, I think the ws 'upgrade' happens over GET and responding with an error to get requests was blocking any upgrade request. Also, I ensured that the other server had no such blocking and this is why I initially assumed that both the servers had the same setup and this was confusing me. Hope this was helpful.






                share|improve this answer















                Okay I have finally found the error. In my code for the server, I had the following:



                server.get('*', async (req, res, nxt) => 
                nxt(new Error('Unsupported Method'));
                );


                I had this to prevent any get requests from being processed since, the API solely relies on post routes. I changed it to the following:



                server.get('*', async (req, res, nxt) => 
                nxt();
                );


                This solved the problem. IMHO, I think the ws 'upgrade' happens over GET and responding with an error to get requests was blocking any upgrade request. Also, I ensured that the other server had no such blocking and this is why I initially assumed that both the servers had the same setup and this was confusing me. Hope this was helpful.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 25 at 13:22

























                answered Mar 25 at 11:45









                Abrar HossainAbrar Hossain

                4133821




                4133821



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid …


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55328461%2fexpress-ws-closing-connection-closes-unexpectedly%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

                    155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

                    Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?