Close connection on ctrl+c

This commit is contained in:
ChillerDragon 2022-11-04 13:07:34 +01:00
parent effa00b001
commit 794915942c
3 changed files with 9 additions and 0 deletions

View file

@ -10,5 +10,9 @@ client.hook_chat do |msg|
puts "chat: #{msg}"
end
Signal.trap('INT') do
client.disconnect
end
client.connect('localhost', 8303, detach: false)
```

View file

@ -68,6 +68,7 @@ class TwClient
end
def disconnect
puts "disconnecting."
unless @netbase.nil?
@netbase.send_packet([NET_CTRLMSG_CLOSE], 0, control: true)
end

View file

@ -31,6 +31,10 @@ client.hook_chat do |msg|
puts "chat: #{msg}"
end
Signal.trap('INT') do
client.disconnect
end
# connect and detach thread
client.connect(args[:ip], args[:port], detach: true)