NodeJS Websocket client stay in pending mode












0















i have a simple js script that "try" to connect to listening server (SocketTest) as shown in the image below. It's really simple, just one line :



var exampleSocket = new WebSocket('ws://127.0.0.1:6601');


So, yes, it is connected but it stay in pending mode finishing by "failed: WebSocket opening handshake timed out"



Maybe i'm wrong somewhere but i don't see it... and it's really simple.
If someone got an idea....



enter image description here



Thanks in advance.










share|improve this question



























    0















    i have a simple js script that "try" to connect to listening server (SocketTest) as shown in the image below. It's really simple, just one line :



    var exampleSocket = new WebSocket('ws://127.0.0.1:6601');


    So, yes, it is connected but it stay in pending mode finishing by "failed: WebSocket opening handshake timed out"



    Maybe i'm wrong somewhere but i don't see it... and it's really simple.
    If someone got an idea....



    enter image description here



    Thanks in advance.










    share|improve this question

























      0












      0








      0








      i have a simple js script that "try" to connect to listening server (SocketTest) as shown in the image below. It's really simple, just one line :



      var exampleSocket = new WebSocket('ws://127.0.0.1:6601');


      So, yes, it is connected but it stay in pending mode finishing by "failed: WebSocket opening handshake timed out"



      Maybe i'm wrong somewhere but i don't see it... and it's really simple.
      If someone got an idea....



      enter image description here



      Thanks in advance.










      share|improve this question














      i have a simple js script that "try" to connect to listening server (SocketTest) as shown in the image below. It's really simple, just one line :



      var exampleSocket = new WebSocket('ws://127.0.0.1:6601');


      So, yes, it is connected but it stay in pending mode finishing by "failed: WebSocket opening handshake timed out"



      Maybe i'm wrong somewhere but i don't see it... and it's really simple.
      If someone got an idea....



      enter image description here



      Thanks in advance.







      javascript node.js websocket






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 14 '18 at 14:14









      StvStv

      367214




      367214
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Without implementing open event do not expect any answer from the server :)
          Try this:



          const WebSocket = require('ws');

          const ws = new WebSocket('ws://127.0.0.1:6601');

          ws.on('open', function open() {
          ws.send('something');
          });


          Edit: The nodejs tag fooled me I thought it is server side.



          The same true on client side, you need to handle onopen event:



          // Connection opened
          exampleSocket.addEventListener('open', function (event) {
          socket.send('Hello Server!');
          });

          // Listen for messages
          exampleSocket.addEventListener('message', function (event) {
          console.log('Message from server ', event.data);
          });





          share|improve this answer


























          • It''s on client side so, i cant use require... even with the onmessage function. thanks @lependu

            – Stv
            Nov 14 '18 at 19:44













          • @Stv edited my answer :)

            – lependu
            Nov 14 '18 at 20:09











          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%2f53302241%2fnodejs-websocket-client-stay-in-pending-mode%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









          1














          Without implementing open event do not expect any answer from the server :)
          Try this:



          const WebSocket = require('ws');

          const ws = new WebSocket('ws://127.0.0.1:6601');

          ws.on('open', function open() {
          ws.send('something');
          });


          Edit: The nodejs tag fooled me I thought it is server side.



          The same true on client side, you need to handle onopen event:



          // Connection opened
          exampleSocket.addEventListener('open', function (event) {
          socket.send('Hello Server!');
          });

          // Listen for messages
          exampleSocket.addEventListener('message', function (event) {
          console.log('Message from server ', event.data);
          });





          share|improve this answer


























          • It''s on client side so, i cant use require... even with the onmessage function. thanks @lependu

            – Stv
            Nov 14 '18 at 19:44













          • @Stv edited my answer :)

            – lependu
            Nov 14 '18 at 20:09
















          1














          Without implementing open event do not expect any answer from the server :)
          Try this:



          const WebSocket = require('ws');

          const ws = new WebSocket('ws://127.0.0.1:6601');

          ws.on('open', function open() {
          ws.send('something');
          });


          Edit: The nodejs tag fooled me I thought it is server side.



          The same true on client side, you need to handle onopen event:



          // Connection opened
          exampleSocket.addEventListener('open', function (event) {
          socket.send('Hello Server!');
          });

          // Listen for messages
          exampleSocket.addEventListener('message', function (event) {
          console.log('Message from server ', event.data);
          });





          share|improve this answer


























          • It''s on client side so, i cant use require... even with the onmessage function. thanks @lependu

            – Stv
            Nov 14 '18 at 19:44













          • @Stv edited my answer :)

            – lependu
            Nov 14 '18 at 20:09














          1












          1








          1







          Without implementing open event do not expect any answer from the server :)
          Try this:



          const WebSocket = require('ws');

          const ws = new WebSocket('ws://127.0.0.1:6601');

          ws.on('open', function open() {
          ws.send('something');
          });


          Edit: The nodejs tag fooled me I thought it is server side.



          The same true on client side, you need to handle onopen event:



          // Connection opened
          exampleSocket.addEventListener('open', function (event) {
          socket.send('Hello Server!');
          });

          // Listen for messages
          exampleSocket.addEventListener('message', function (event) {
          console.log('Message from server ', event.data);
          });





          share|improve this answer















          Without implementing open event do not expect any answer from the server :)
          Try this:



          const WebSocket = require('ws');

          const ws = new WebSocket('ws://127.0.0.1:6601');

          ws.on('open', function open() {
          ws.send('something');
          });


          Edit: The nodejs tag fooled me I thought it is server side.



          The same true on client side, you need to handle onopen event:



          // Connection opened
          exampleSocket.addEventListener('open', function (event) {
          socket.send('Hello Server!');
          });

          // Listen for messages
          exampleSocket.addEventListener('message', function (event) {
          console.log('Message from server ', event.data);
          });






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 14 '18 at 20:09

























          answered Nov 14 '18 at 14:45









          lependulependu

          714314




          714314













          • It''s on client side so, i cant use require... even with the onmessage function. thanks @lependu

            – Stv
            Nov 14 '18 at 19:44













          • @Stv edited my answer :)

            – lependu
            Nov 14 '18 at 20:09



















          • It''s on client side so, i cant use require... even with the onmessage function. thanks @lependu

            – Stv
            Nov 14 '18 at 19:44













          • @Stv edited my answer :)

            – lependu
            Nov 14 '18 at 20:09

















          It''s on client side so, i cant use require... even with the onmessage function. thanks @lependu

          – Stv
          Nov 14 '18 at 19:44







          It''s on client side so, i cant use require... even with the onmessage function. thanks @lependu

          – Stv
          Nov 14 '18 at 19:44















          @Stv edited my answer :)

          – lependu
          Nov 14 '18 at 20:09





          @Stv edited my answer :)

          – lependu
          Nov 14 '18 at 20:09




















          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%2f53302241%2fnodejs-websocket-client-stay-in-pending-mode%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

          List item for chat from Array inside array React Native

          Thiostrepton

          Caerphilly