
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
WebsocketParser is a RFC6455 compliant parser for websocket messages written in Ruby. It is intended to write websockets servers in Ruby, but it only handles the parsing of the WebSocket protocol, leaving I/O to the server.
Add this line to your application's Gemfile:
gem 'websocket_parser'
And then execute:
$ bundle
Or install it yourself as:
$ gem install websocket_parser
The simplest way to use the websocket parser is to create a new one, fetch it with data and query it for new messages.
require 'websocket_parser'
parser = WebSocket::Parser.new
parser.append data
parser.next_message # return next message or nil
parser.next_messages # return an array with all parsed messages
# To send a message:
socket << WebSocket::Message.new('Hi there!').to_data
Only text or binary messages are returned on the parse methods. To intercept control frames use the parser's callbacks.
In addition to return values, you can register callbacks to get notified when a certain event happens.
require 'websocket_parser'
socket = # Handle I/O with your server/event loop.
parser = WebSocket::Parser.new
parser.on_message do |m|
puts "Received message #{m}"
end
parser.on_error do |m|
puts "Received error #{m}"
socket.close!
end
parser.on_close do |status, message|
# According to the spec the server must respond with another
# close message before closing the connection
socket << WebSocket::Message.close.to_data
socket.close!
puts "Client closed connection. Status: #{status}. Reason: #{message}"
end
parser.on_ping do |payload|
socket << WebSocket::Message.pong(payload).to_data
end
parser << socket.read(4096)
git checkout -b my-new-feature
)git commit -am 'Added some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that websocket_parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.