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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:10:10+00:00 2026-05-26T16:10:10+00:00

I have a little WebSocket chat demo that I am working on ( based

  • 0

I have a little WebSocket chat demo that I am working on (based on this code). However, the part that doesn’t seem to be working is when a connection is closed between a client and the server, I want to notify all the subscribers that the user has “left the chatroom”. I thought that the server would be notified/run the onclose function when the client connection was dropped, but maybe that’s not how WebSockets work.

Here’s my EventMachine code:

  ws.onclose do
    puts "Connection closed"
    ws.send ({:type => 'status', :message => "#{@subscribers[subscriber_id]} has left the chatroom"}.to_json)
    @main_channel.unsubscribe(subscriber_id)
  end
  • 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-05-26T16:10:11+00:00Added an answer on May 26, 2026 at 4:10 pm

    You are trying to send data to a WebSocket that was just closed, that won’t work. You probably want to just push a message to the Queue like:

    ws.onclose do
      puts "Connection closed"
      msg = {:type => 'status', :message => "#{@subscribers[subscriber_id]} has left the chatroom"}.to_json
      @main_channel.push(msg)
      @main_channel.unsubscribe(subscriber_id)
    end
    

    That way the message will be send to all subscribers.

    Best regards

    Tobias

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

Sidebar

Related Questions

I have been working on this for a while now and, unfortunately have little
I have little working knowledge of python. I know that there is something called
I have little question about how web browser retrieve webpage? I know this User
Good day. I have little usage of Flash CS4, however i have to build
Both ideone.com and codepad.org have Little-Endian architechtures. I want to test my code on
I have a problem with a part of a project i am working on.
I have little Silverlight app that needs to make queries to server, is it
I have little quiz game I've working on and am tracking correct answers. I
I have little problem with printing data like this, I have written script like
I have little code like: using (WebClient wc = new WebClient()) { wc.Proxy =

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.