2012-07-12 01:59:11 +00:00
|
|
|
require 'date'
|
|
|
|
require 'time'
|
|
|
|
require 'socket'
|
|
|
|
|
|
|
|
DATEFMT = '%Y%m%d%H%M%S'
|
|
|
|
|
|
|
|
def recordify(msg)
|
|
|
|
code = '%-31s' % 'DERP'
|
|
|
|
num = '%-12d' % (rand.to_s.tr('.', '0')[0,5]).to_i
|
|
|
|
timestamp = Time.now.strftime(DATEFMT)
|
|
|
|
len = '%-6d' % msg.length
|
|
|
|
"#{code}#{num}#{len}#{timestamp}#{msg.gsub(/\r/, '\r').gsub(/\n/, '\n')}\r\n"
|
|
|
|
end
|
|
|
|
|
|
|
|
def main
|
|
|
|
print "What to say?: "
|
|
|
|
msg = gets
|
|
|
|
TCPSocket.open('127.0.0.1', 15778) do |sock|
|
|
|
|
sock.send(recordify(msg), 0)
|
|
|
|
response = sock.recv(66)
|
|
|
|
sock.close
|
|
|
|
|
|
|
|
puts "raw response --> #{response.inspect}"
|
2012-07-12 13:19:10 +00:00
|
|
|
code = response[0,31].to_s.strip
|
|
|
|
num = response[31,12].to_s.strip
|
|
|
|
raw_timestamp = response[49,14].to_s.strip
|
2012-07-12 01:59:11 +00:00
|
|
|
timestamp = DateTime.strptime(raw_timestamp, DATEFMT)
|
|
|
|
|
|
|
|
puts "code: '#{code}'"
|
|
|
|
puts "num: '#{num}'"
|
|
|
|
puts "timestamp: '#{timestamp}'"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if __FILE__ == $0
|
|
|
|
main
|
|
|
|
end
|