
Security News
Node.js Moves Toward Stable TypeScript Support with Amaro 1.0
Amaro 1.0 lays the groundwork for stable TypeScript support in Node.js, bringing official .ts loading closer to reality.
= Cool.io-WebSocket
Cool.io-WebSocket is a WebSocket server implementation based on Cool.io, a high performance event-driven I/O library for Ruby.
This library conforms to WebSocket draft-75 and draft-76.
== Installation
gem install cool.io-websocket
== Examples
See examples/README.md[http://github.com/maxjustus/cool.io-websocket/tree/master/examples/] for details.
=== Simple echo server
require 'rubygems'
require 'cool.io-websocket'
class MyConnection < Cool.io::WebSocket
def on_open
puts "WebSocket opened"
send_message("Hello, world!")
end
def on_message(data)
puts "WebSocket data received: '#{data}'"
send_message("echo: #{data}")
end
def on_close
puts "WebSocket closed"
end
end
host = '0.0.0.0'
port = '8080'
server = Cool.io::WebSocketServer.new(host, port, MyConnection)
server.attach(Cool.io::Loop.default)
Cool.io::Loop.default.run
=== Publisher/Subscriber-style message routing require 'rubygems' require 'cool.io-websocket'
class PubSub
def initialize
@subscriber = {}
@seqid = 0
end
def subscribe(&block)
sid = @seqid += 1
@subscriber[sid] = block
return sid
end
def unsubscribe(key)
@subscriber.delete(key)
end
def publish(data)
@subscriber.each_value {|block|
block.call(data)
}
end
end
$pubsub = PubSub.new
class MyConnection < Cool.io::WebSocket
def on_open
puts "WebSocket opened"
@sid = $pubsub.subscribe {|data|
send_message data
}
end
def on_message(data)
puts "WebSocket data received, broadcasting: '#{data}'"
$pubsub.publish(data)
end
def on_close
puts "WebSocket closed"
$pubsub.unsubscribe(@sid)
end
end
host = '0.0.0.0'
port = ARGV[0] || 8080
server = Cool.io::WebSocketServer.new(host, port, MyConnection)
server.attach(Cool.io::Loop.default)
puts "start on #{host}:#{port}"
Cool.io::Loop.default.run
== Learn more
== License
Copyright (c) 2010 FURUHASHI Sadayuki
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Unknown package
We found that cool.io-websocket demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Amaro 1.0 lays the groundwork for stable TypeScript support in Node.js, bringing official .ts loading closer to reality.
Research
A deceptive PyPI package posing as an Instagram growth tool collects user credentials and sends them to third-party bot services.
Product
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.