Fix reconnecting

This commit is contained in:
ChillerDragon 2022-11-04 12:55:01 +01:00
parent 57a8f0bcc7
commit 0e42839e74
3 changed files with 12 additions and 9 deletions

View file

@ -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" +

View file

@ -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

View file

@ -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