require "option_parser" require "./test-ws" uri = "ws://localhost:1234/pong.JSON" rounds = 5 OptionParser.parse do |parser| parser.on "-r rounds", "--rounds rounds", "Rounds" do |r| rounds = r.to_i end parser.on "-u uri", "--uri uri", "URI" do |opturi| uri = opturi end parser.on "-h", "--help", "Show this help" do puts parser exit 0 end end def multiple_messages_and_responses(tws : TestWS, data) tws.send 1, data tws.send 2, data tws.send 3, data tws.send 4, data tws.send 5, data response = tws.read puts "1. received a message: #{response}" pp! response response = tws.read puts "2. received a message: #{response}" pp! response response = tws.read puts "3. received a message: #{response}" pp! response response = tws.read puts "4. received a message: #{response}" pp! response response = tws.read puts "5. received a message: #{response}" pp! response end def single_message_and_response(tws : TestWS, data) tws.send 1, data response = tws.read pp! response end begin tws = TestWS.new uri # puts "connection done: sending pong" data = STDIN.gets_to_end data = data.chomp rounds.times do |i| single_message_and_response tws, "#{data} #{i}" end # puts "closing the connection" tws.close tws.read rescue e puts "Exception: #{e}" end