A simulation container based on Celluloid.
routes:
Sim::Net::Router.define do |router|
router.forward :test, to: Example::SimpleHandler # allow everybody
router.forward :admin, to: Example::SimpleHandler do |player_id|
Player.find(player_id).admin? # allow only admins
end
end
handle incoming player events and broadcast them back
{scope: 'test', action: 'reverse', args: 'hello world'}
class Example::SimpleHandler < Sim::Net::MessageHandler::Base
def reverse text
queue_player_event do |player_id|
broadcast player_id, scope: 'test', action: 'reverse', answer: text.reverse
end
end
end
execute simulation. The class must have a reader to the simulated object and provide a sim
method
class Tick
attr_reader :object
def initialize object
@object = object
end
def sim
# calculate next object state
end
end
- ruby 2.4.x
- node 8.3.x
sim server:
$> bundle
middleware:
$> cd examples/node
$> npm install
$> webpack
sim server:
$> ruby examples/server/boot.rb
middleware:
$> cd examples/node && node --harmony app.js
create a npm link to have all the recent changes in the examples
in folder node issue:
$>npm link
then in examples/node create the sym link like so:
$>npm link simulator-middleware
for better output comment out Celluloid.logger = nil
in spec_helper.rb
test unix socket with netcat:
$> nc -U tmp/sockets/pong.sock