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 8374815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:00:44+00:00 2026-06-09T15:00:44+00:00

How does WebSockets exactly work? Implementing them seemed weird. First you construct the object

  • 0

How does WebSockets exactly work? Implementing them seemed weird.

First you construct the object with the address, then you define the callbacks like onopen which is called when the connection is opened. Now how does that happen if I told the websocket to connect while constructing it? If the constructor connects in async way, is it guaranteed that my onopen will be called.

To sum it up:

1) When does the websocket decide to connect, when I declare all callbacks?

2) Is send() method async? If so, is there a way to call it sync?

EDIT: I have found out send() is async, there is a bufferedAmount attribute that returns the amount of data that is buffered to be sent. However, the second part of the second question still stands.

  • 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-09T15:00:45+00:00Added an answer on June 9, 2026 at 3:00 pm

    I’ve found a good way to explain how this part of an event loop works is this:

    In an event loop, everything runs asynchronously, except for your code.

    Consecutive statements will always be executed before the next event loop iteration happens. This means that you can safely assign event listeners to the ws object, because you know that it cannot call them before current iteration completes.

    As for sending, as you noticed correctly, those values are generally buffered. However, it’s probably a bad idea to send any messages before the onopen event is fired, as you’re buffering messages on a not yet opened connection.

    I hope this answers your question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does the G'MIC (Grey's Magic Image Converter) library work on iOS ? what steps
Does BlackBerry OS 6's HTML5 implementation support websockets? There was a page on BB's
using node.js and socket.io to serve websockets does socket.io need to be listening on
Does the browser in the Wii support websockets? I know the Wii uses opera,
Does GWT support HTML5? I mean especially Canvas and WebSockets? Regards
I am using Netty websockets and everything seems to work fine except this minor
Does anyone know if it's possible to use websockets on Cloudbees or Jelastic. I
I've understood that Heroku does not offer support for websockets, and still one can
Does anyone know if there is a way to generate different code in the
Does COUNT(*) have any significant impact for MySQL performance if query already has GROUP

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.