前提・実現したいこと
websocket-client-simpleを使用していますが、時々(数時間に1度程度)次のようなエラーが出てしまします。
エラー発生時には再度websocketを最初から繋ぎなおすという処理をしたいのですが、どのように実装すればいいかわかりません。
アドバイス頂ければ大変助かります。
発生している問題・エラーメッセージ
#<Errno::ECONNRESET: An existing connection was forcibly closed by the remote host.>
該当のソースコード
Ruby
1 2 ws = WebSocket::Client::Simple.connect 'wss://ws.xxxxxxxxxxxxxx.com/json-rpc' 3 4 ws.on :open do 5 puts "Open WebSocket #{Time.now}" 6 ws.send(json) 7 end 8 9 ws.on :message do |msg| 10 loop{ 11 data = JSON.parse(msg.data) 12 if data["method"] == "channelMessage" then 13 puts data["params"]["message"] 14 end 15 } 16 end 17 18 ws.on :close do |e| 19 p e 20 end 21 22 ws.on :error do |e| 23 p e 24 end
試したこと
ws.on :error do |e| の後に再度、頭からやり直す。という命令をかければいいのですが、何をかけばいいのかわかりません。。
あなたの回答
tips
プレビュー