Friday, January 28, 2011

Single line socket puts

#!/usr/bin/env ruby
require 'socket'

send_msg = ARGV[1]
send_msg ||= "[nil msg]"
puts "MSG  >>>#{send_msg}<<<"
port = ARGV[0].to_i
puts "PORT >>>#{port}<<<"

TCPSocket.open("localhost", port) do |sk|
  sk.puts send_msg
  puts "SENT >>>#{send_msg}<<<"

  recv_msg = sk.gets
  puts "RECV >>>#{recv_msg.chomp}<<<"
end

No comments:

Post a Comment