Third network level requires to sum 4 integers and send result. They are provided by the server. Nothing special just use of pack and unpack methods.
Code:
Code:
#!/usr/bin/ruby1.9.1
require "socket"
sock = TCPSocket.new('127.0.0.1','2997')
result = 0
4.times do |ind|
is = sock.read(4)
puts is.unpack('l')[0]
result += is.unpack('l')[0]
end
puts result
sock.puts [result].pack('l')
puts sock.gets
sock.close
Proof:
No comments:
Post a Comment