Fix reconnecting
This commit is contained in:
parent
57a8f0bcc7
commit
0e42839e74
|
@ -20,6 +20,10 @@ class NetChunk
|
|||
@next = data[chunk_end..] if data.size > chunk_end
|
||||
end
|
||||
|
||||
def self.reset
|
||||
@@sent_vital_chunks = 0
|
||||
end
|
||||
|
||||
def to_s
|
||||
"NetChunk\n" +
|
||||
" msg=#{msg} sys=#{sys}\n" +
|
||||
|
|
|
@ -45,6 +45,7 @@ class TwClient
|
|||
puts "client token #{@client_token}"
|
||||
@netbase = NetBase.new
|
||||
@netbase.client_token = @client_token
|
||||
NetChunk.reset
|
||||
@ip = ip
|
||||
@port = port
|
||||
puts "connecting to #{@ip}:#{@port} .."
|
||||
|
@ -65,6 +66,7 @@ class TwClient
|
|||
end
|
||||
|
||||
def disconnect
|
||||
@netbase.send_packet([NET_CTRLMSG_CLOSE], 0, control: true)
|
||||
@signal_disconnect = true
|
||||
@s.close
|
||||
end
|
||||
|
|
15
sample.rb
15
sample.rb
|
@ -31,14 +31,11 @@ client.hook_chat do |msg|
|
|||
puts "chat: #{msg}"
|
||||
end
|
||||
|
||||
client.connect(args[:ip], args[:port], detach: true)
|
||||
|
||||
sleep 2
|
||||
client.disconnect()
|
||||
|
||||
sleep 1
|
||||
client.connect(args[:ip], args[:port], detach: false)
|
||||
|
||||
loop do
|
||||
sleep 2
|
||||
puts "reconnecing .."
|
||||
client.disconnect()
|
||||
sleep 1
|
||||
client.connect(args[:ip], args[:port])
|
||||
sleep 200
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue