
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.
websocket_sequential_client
Advanced tools
This ruby gem library allows you to access a WebSocket server in a sequential way instead of an event-driven way.
Provides access to a WebSocket server in a sequential way.
Many gem libraries for WebSocket client use event-driven style.
This style has many advantages, but it's not so easy to understand.
This gem library provides a simple and sequential access to a WebSocket server.
Independent from eventmachine and other frameworks.
You can use this gem library with/without eventmachine and other frameworks.
Eventmachine is a great and useful library, but it uses some global functions, such as EM.run
, EM.stop
and so on, so it might conflicts with your environment.
This gem library does not depends on any frameworks, so you can use it in your environment.
If you need performance and/or scalability, you should use the other great libraries, such as em-websocket.
Add this line to your application's Gemfile:
gem 'websocket_sequential_client'
And then execute:
$ bundle
Or install it yourself as:
$ gem install websocket_sequential_client
Call send
and recv
to communicate with the server.
require "websocket_sequential_client"
WebSocketSequentialClient::WebSocket.open "ws://server-url" do |ws|
ws.send "Hello"
puts ws.recv
end
Note: recv
method is a blocking method. It will wait until a message is sent from the server.
# coding: utf-8
require "websocket_sequential_client"
ws = WebSocketSequentialClient::WebSocket.new "ws://server-url"
# `send` method guesses whether the argument is text or binary based on the encoding.
# The encoding of "Hello" is UTF-8, so the messages is sent as text.
ws.send "Hello"
# You can also use `send_text` method.
ws.send_text "World"
# The following lines send binary messages
# because the argument has ASCII-8BIT encoding.
ws.send [0,1,2,3].pack("C*")
ws.send "example".b
# Of course, `send_binary` is supported.
ws.send_binary "binary message"
# You can receive messages from the server with `recv`.
# If the server sent "text" message, msg has UTF-8 encoding.
# In the case of "binary" message, msg has ASCII-8BIT encoding.
msg = ws.recv
ws.close
ping
and pong
frames are sent in background, so you need not to handle these frames.
require "websocket_sequential_client"
# `ping` is enabled as default. The interval is 20s.
ws = WebSocketSequentialClient::WebSocket.new "ws://server-url"
#...
ws.close
# You can disable `ping`.
ws = WebSocketSequentialClient::WebSocket.new "ws://server-url", ping: false
#...
ws.close
# You can change the interval of `ping` to 10s.
ws = WebSocketSequentialClient::WebSocket.new "ws://server-url", ping: { interval: 10 }
#...
ws.close
You can send additional headers with the request of HTTP handshake.
require "websocket_sequential_client"
# Add "Cookie" field to the HTTP request.
ws = WebSocketSequentialClient::WebSocket.new "ws://server-url", headers: { "Cookie" => "value1" }
#...
ws.close
FAQs
Unknown package
We found that websocket_sequential_client 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.