#!/usr/bin/env ruby

require "./client.rb"
require "socket"

def do_it(hn,port)
  port = port.to_i
  puts "connection to host #{hn}:#{port}"
  socket = TCPSocket.new(hn,port)
  GameClient.new(socket).game_loop(socket)
end

if $DEBUG  
  $protocoll = File.open("protocoll"+Process.pid.to_s,"w")
  
  class TCPSocket
    alias old_gets gets
    alias old_puts puts
    
    def gets
      s=old_gets
      $protocoll.puts " --> #{s}"
      s
    end
    
    def puts(*x)
      x.each { |s| $protocoll.puts " <-- #{s} " }
      old_puts *x
    end
  end
end

do_it(ARGV[0] || "localhost",
      ARGV[1] || "20020");
