Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I tried this and it's working:</p> <pre><code>#!/usr/bin/env ruby require 'eventmachine' module EchoServer def post_init puts "-- someone connected to the echo server!" end def receive_data data send_data "&gt;&gt;&gt;you sent: #{data}" close_connection if data =~ /quit/i end def unbind puts "-- someone disconnected from the echo server!" end end EventMachine::run { EventMachine::start_server "127.0.0.1", 8081, EchoServer EventMachine::start_server "127.0.0.1", 8082, EchoServer EventMachine::start_server "127.0.0.1", 8083, EchoServer } </code></pre> <p>Here you get 3 echo services with different ports. (I was too lazy to implement different services.)</p> <p>So, it's very easy to build a huge multi service wrapper.</p> <hr> <p><strong>Update</strong></p> <p>Simple code example for condition based start of a EM server:</p> <pre><code>#!/usr/bin/env ruby # encoding: utf-8 require 'eventmachine' module EchoServer def post_init puts "-- someone connected to the echo server!" end def receive_data data send_data "&gt;&gt;&gt;you sent: #{data}" close_connection if data =~ /quit/i end def unbind puts "-- someone disconnected from the echo server!" end end $check_ok = false EventMachine::run { puts "checker var is: #{$check_ok}" EventMachine::start_server "127.0.0.1", 8081, EchoServer EventMachine::start_server "127.0.0.1", 8082, EchoServer puts "echos on 8081 and 8082 started." # periodic timer check - every 1 sec EventMachine.add_periodic_timer(1) { if $check_ok EventMachine::start_server "127.0.0.1", 8083, EchoServer $check_ok = false puts "echo on 8083 started!" end } # timer triggered after 10 secs - only once! EventMachine.add_timer(10) { $check_ok = true puts "checker var is #{$check_ok} now!" } } </code></pre> <p>In this example the echo server on port 8083 is started ~10 secs after app start. Try to <code>telnet localhost 8083</code> before and after this timer, you'll see the effect.</p> <p>You also can use values lower than 1 sec like 0.01 for every 1/100th sec checks.</p> <p>This might be your starting point for your own ideas. The periodic timer is your internal loop, where you hook in your conditional checks for starting further services.</p> <hr> <p>Good tutorial (PDF): <a href="http://everburning.com/wp-content/uploads/2009/02/eventmachine_introduction_10.pdf" rel="noreferrer">eventmachine introduction</a> (<a href="http://everburning.com/news/eventmachine-introductions/" rel="noreferrer">blog post</a>)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload