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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:18:09+00:00 2026-06-04T04:18:09+00:00

I have a rails app I am running on thin server to utilize the

  • 0

I have a rails app I am running on thin server to utilize the EventMachine run loop. The problem is that I would like to be able to include em-websocket to process information coming in from a ws and stop and start the websocket without stopping the EM run loop. This is how I am starting the websocket.

EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 8080) do |ws|
  ws.onopen { }
  ws.onclose { }
  ws.onmessage { |msg| }
end

The problem is in the start/stop code. From em-websocket’s docs

#Start WebSocket
def self.start(options, &blk)
  EM.epoll
  EM.run do

    trap("TERM") { stop }
    trap("INT")  { stop }

    EventMachine::start_server(options[:host], options[:port],
      EventMachine::WebSocket::Connection, options) do |c|
      blk.call(c)
    end
  end
end


#Stop WebSocket
def self.stop
  puts "Terminating WebSocket Server"
  EventMachine.stop
end

The problem is that the internal em-websocket code does not track the signature coming from EM:start_server to be able to call EventMachine::stop_server(signature) to shut it down. Is there a way I can override these functions without modifying em-websocket so I can safely start / stop these websockets? I would like if it performed more like the standart Eventmachine server.

  • 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-04T04:18:10+00:00Added an answer on June 4, 2026 at 4:18 am

    Seems to me you don’t need to use EM::Websocket.start(). Instead write your own start/stop code, then you can manage the signature yourself.

    # start a ws server and return the signature
    # caller is responsible for +trap+ing to stop it later using said signature.
    def start_ws_server(options, &blk)
      return EventMachine::start_server(options[:host], options[:port],
        EventMachine::WebSocket::Connection, options) do |c|
        blk.call(c)
      end
    end
    
    # stop a previously started ws server
    def stop_ws_server(signature)
      EventMachine::stop_server signature
    end
    

    So now you can start and capture the signature and stop it later using it. No trap code in the start method as at that point the signature is unknown. Since you are capturing the sig outside the method you can trap outside too and use the stored sig there.

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

Sidebar

Related Questions

I have a Rails app that is running on a production server with Apache
I have a single-threaded Rails app running on thin in single-threaded mode on Heroku
I have a ruby on rails app running a server and sometimes it needs
I have a Ruby on Rails app running on my server, and I can't
I have an app running Rails 2.3.5 that has a JSON API for much
I have an app running on my production server that uses the pg gem
I have got a Rails app running which displays data that is generated by
I have a rails app running on my Apache server via Passenger. Occassionally I
I have a Rails app that is running on port 8080 that I need
I have a rails app (running on version 2.2.2) that has a model called

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.