Sha256: 554db766491633ba754955b0ffb70d5d8e738e262cc942e15a6a310b8e50018c

Contents?: true

Size: 1007 Bytes

Versions: 26

Compression:

Stored size: 1007 Bytes

Contents

#!/usr/bin/env ruby

require 'eventmachine'
require 'socket'

module Flapper

  def receive_data data
    send_data ">>>you sent: #{data}"
    close_connection if data =~ /quit/i
  end

end

def local_ip
  # turn off reverse DNS resolution temporarily
  orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true

  UDPSocket.open do |s|
    s.connect '64.233.187.99', 1
    s.addr.last
  end
ensure
  Socket.do_not_reverse_lookup = orig
end

start_every = 120
stop_after  = 60
bind_ip     = local_ip
bind_port   = 12345
EM.run {

  puts "#{Time.now}: starting server"
  server_init = EM.start_server bind_ip, bind_port, Flapper
  EM.add_timer(stop_after) do
    puts "#{Time.now}: stopping server"
    EM.stop_server(server_init)
  end

  EM.add_periodic_timer(start_every) do
    puts "#{Time.now}: starting server"
    server = EM.start_server bind_ip, bind_port, Flapper
    EM.add_timer(stop_after) do
      puts "#{Time.now}: stopping server"
      EM.stop_server(server)
    end
  end
}

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
flapjack-0.6.53 bin/flapper
flapjack-0.6.52 bin/flapper
flapjack-0.6.51 bin/flapper
flapjack-0.6.50 bin/flapper
flapjack-0.6.49 bin/flapper
flapjack-0.6.48 bin/flapper
flapjack-0.6.47 bin/flapper
flapjack-0.6.46 bin/flapper
flapjack-0.6.45 bin/flapper
flapjack-0.6.44 bin/flapper
flapjack-0.6.43 bin/flapper
flapjack-0.6.42 bin/flapper
flapjack-0.6.41 bin/flapper
flapjack-0.6.40 bin/flapper
flapjack-0.6.39 bin/flapper
flapjack-0.6.38 bin/flapper
flapjack-0.6.37 bin/flapper
flapjack-0.6.36 bin/flapper
flapjack-0.6.35 bin/flapper
flapjack-0.6.34 bin/flapper