Disconnect before connecting

This commit is contained in:
ChillerDragon 2022-11-04 13:04:51 +01:00
parent 0e42839e74
commit effa00b001
2 changed files with 11 additions and 5 deletions

View file

@ -38,6 +38,8 @@ class TwClient
return
end
end
disconnect
@signal_disconnect = false
@ticks = 0
# me trying to write cool code
@client_token = (1..4).to_a.map { |_| rand(0..255) }
@ -66,9 +68,13 @@ class TwClient
end
def disconnect
@netbase.send_packet([NET_CTRLMSG_CLOSE], 0, control: true)
unless @netbase.nil?
@netbase.send_packet([NET_CTRLMSG_CLOSE], 0, control: true)
end
unless @s.nil?
@s.close
end
@signal_disconnect = true
@s.close
end
private

View file

@ -31,11 +31,11 @@ client.hook_chat do |msg|
puts "chat: #{msg}"
end
# connect and detach thread
client.connect(args[:ip], args[:port], detach: true)
# after 2 seconds reconnect
# and block the main thread
sleep 2
client.disconnect()
sleep 1
client.connect(args[:ip], args[:port], detach: false)