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