Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8706421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:36:38+00:00 2026-06-13T03:36:38+00:00

Hi everyone and thanks for reading this. I’m using NodeJS with WS module on

  • 0

Hi everyone and thanks for reading this.
I’m using NodeJS with WS module on server side and HTML5 WebSocket API in Firefox on client side. The operating system is windows 7 64 bit. Whenever I make a connection from the client to server, the connection forms instantaneously, but when I send some data there is a huge delay. Sometimes the messages seem to reach the server instantly, other times they reach after some seconds and even minutes and most of the time they fail to reach the server at all. I’m attaching the code from both client and server sides. If someone can help me, I’d be really thankful.

Client Side Code

<!doctype html>
<html>
    <head>
        <script>
            var ws = new WebSocket("ws://localhost:5225");
            ws.onopen = function (){
                alert("Sending");
                ws.send("SOME DATA !");
            }
        </script>
    </head>
    <body>
    </body>
</html>

Server Side Code

var WebSocketServer = require('./ws').Server;
var wss = new WebSocketServer({port:5225});
var ws;

wss.on('connection',function (wsock){
    console.log("Connection Recieved");

    ws = wsock;

    ws.on('message',onnMessage);

    ws.on('close',onnClose);
});

function onnMessage(data){
        console.log("Data Recieved : "+data);
}

function onnClose(){
        console.log("Connection closed");
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T03:36:39+00:00Added an answer on June 13, 2026 at 3:36 am

    I am unable to test at the moment, but I believe the issue is your websocket variable(ws) is out of scope inside the .onopen() event or the variable is being freed by the garbage collector before the event fires. To fix this, create the socket as a global(or to an object in the global scope):

    <script>
        window.ws = new WebSocket("ws://localhost:5225");
        ws.onopen = function (){
            alert("Sending");
            ws.send("SOME DATA !");
        }
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello everyone and thanks in advance for reading this.. I have the following html
Hello and thanks to everyone for reading my question. I've been working on a
Thanks everyone for taking the time to read this. I have styled my navigation
Thanks to everyone out there helping newbies like me. So far I have this:
This is my first question. Thanks to everyone who contributes to this site, it's
Hello everyone and thanks for reading... I'm a Mono / Web developer and was
Firstly I would just like to thank everyone for reading this and answering my
Update: Thanks for everyone who helped out - the answer to this one lay
Thanks to everyone who helped me with my last question. This is a similar
Hello everyone and thanks for reading. For means of QA, I want to setup

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.