Sha256: 4aab584804e487d1f01ab9199ffc078150012f3bd7947383e9ef24af211fde5e

Contents?: true

Size: 1.43 KB

Versions: 16

Compression:

Stored size: 1.43 KB

Contents

#!/usr/bin/env ruby
require 'benchmark'
Dir.chdir(File.expand_path(File.join('..', '..', 'lib'), __FILE__))
require 'bundler/setup'
require 'plezi'
class WebsocketSample
  # every request that routes to this controller will create a new instance
  def initialize
  end

  # Http methods are available
  def index
    'Hello World!'
  end

  # RESTful methods are available
  def show
    "showing object with id: #{params['id']}..."
  end

  # called before the protocol is swithed from HTTP to WebSockets.
  #
  # this allows setting headers, cookies and other data (such as authentication)
  # prior to opening a WebSocket.
  #
  # if the method returns false, the connection will be refused and the remaining routes will be attempted.
  def pre_connect
    true
  end

  # called immediately after a WebSocket connection has been established.
  # it blocks all the connection's actions until the `on_open` initialization is finished.
  def on_open
  end

  # called when new data is recieved
  #
  # data is a string that contains binary or UTF8 (message dependent) data.
  def on_message(data)
    puts "Websocket got: #{data}"
    write ">> #{data}"
  end

  # called once, AFTER the connection was closed.
  def on_close
  end

  # called once, during **server shutdown**, BEFORE the connection is closed.
  # this will only be called for connections that are open while the server is shutting down.
  def on_shutdown
  end
end
Plezi.route '/', WebsocketSample

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
plezi-0.16.4 bin/hello_world
plezi-0.16.3 bin/hello_world
plezi-0.16.2 bin/hello_world
plezi-0.16.1 bin/hello_world
plezi-0.16.0 bin/hello_world
plezi-0.15.1 bin/hello_world
plezi-0.15.0 bin/hello_world
plezi-0.14.9 bin/hello_world
plezi-0.14.8 bin/hello_world
plezi-0.14.7 bin/hello_world
plezi-0.14.6 bin/hello_world
plezi-0.14.5 bin/hello_world
plezi-0.14.4 bin/hello_world
plezi-0.14.3 bin/hello_world
plezi-0.14.2 bin/hello_world
plezi-0.14.1 bin/hello_world