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

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현