shokai / websocket-client-simple Goto Github PK
View Code? Open in Web Editor NEWSimple WebSocket Client on Ruby
Home Page: https://rubygems.org/gems/websocket-client-simple
License: MIT License
Simple WebSocket Client on Ruby
Home Page: https://rubygems.org/gems/websocket-client-simple
License: MIT License
Blocks that were provided to the EventEmmiter as callbacks are evaluated inside the Client class. It's easy to check:
ws.on :open do
puts self
end
Will output:
#<WebSocket::Client::Simple::Client:0x007f890bc50698>
So code like follows wont work:
state = :initial
ws.on :open do
state = :connected
end
What's the convenient way to access the initial environment where the block was created?
定期的に空パケットを送って接続が生きているか確認するべき
If I pass a random url as parameter the client doesn't raise any error
for test server
I've found two cases where ws.on :close is not triggered, both involving the server going down. First is with a em-websocket server, and the second is with a secure: true
connection with a WebSocket-EventMachine-Server server.
A possible fix is to replace sleep 1
with close
in client.rb.
To reproduce, use the websocket-client-simple example with either the em-websocket example or with the WebSocket-EventMachine-Server example modified for TLS.
I'm not sure how handle close code with websocket gem...
It is actually a bug in the eventemitter gem, and serious one. Event callbacks for the socket are called on the wrong context, set by the emitter. It took me several hours to trace. I suggest to fix emitter or refrain of using it.
Sample:
`
me = self
@ws = WebSocket::Client::Simple.connect(ws_url)
@ws.on(:open) {
if me != self
puts "\n\n\nSelf is set to wrong in the callback in #{RUBY_VERSION}\n\n\n"
end
}
`
I have a syntax error.
When the syntax error is inside of on :event block, it is silenced.
Hi,
Is it possible to send headers to the web socket when first making a connection? I was looking to replicate this code that uses curl ( https://gist.github.com/htp/fbce19069187ec1cc486b594104f01d0 ) using your web socket client.
The client defines a #send method that overrides the default Object#send method of a plain Ruby Object. This can cause problems when trying to use SimpleDelegator
to wrap the client class, as the Object#send
method is called on the SimpleDelegator
wrapper object instead of it being delegated to the client object.
ws = WebSocket::Client::Simple.connect url
ws.on :open do
ws.send("foo") ## default :type => :text
ws.send(bynary_data, :type => :binary)
end
I have Java websocket server running on which I am trying to connect using websocket-client-simple client.
Some times on :open is not triggered, even not and exception in on :error or in rescue block.
Is it possible to send a raw piece of data over socketio? Like just a plain string
Is there any support for sending ping frames?
I have nodejs socket server that I connect to.
The ruby client constantly closes the connection after a minute or so and it does not reconnect automatically.
Am I supposed to send some kind of ping to keep the connection alive?
There's no way to check @handshake
is true or not from outside.
So it's difficult to know websocket status.
Because the Client currently spawns the socket reading thread in the object initializer, there's a small window where the user of this library hasn't had a chance to set up their event handlers yet, but the connection can emit events. For illustration:
ws = WebSocket::Client::Simple.connect 'ws://example.com:8888'
# a :message or :open event could be emitted in this window of time, before we
# have a chance to register the handler below, and it will be lost permanently
ws.on :open do |msg|
puts msg.data
end
Possible solutions include:
# the connection thread is not actually started until this method is called, after we
# have a chance to register our handlers
ws.start
or:
ws = WebSocket::Client::Simple.connect('ws://example.com:8888') do |ws|
# we have a chance to register our handlers during the constructor,
# before the thread is started
ws.on :open do |msg|
puts msg.data
end
end
切断時にcloseフレーム送ってない気がするので調べる
Hi,
I have an old repo which uses Ruby 1.9.3 and does web socket client connections. Is it possible to use this gem with Ruby 1.9.3?
Currently I am getting error while installing:
E:\Jmyapp>gem install websocket-client-simple
ERROR: Error installing websocket-client-simple:
websocket requires Ruby version >= 2.0.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.