Professional Documents
Culture Documents
s2 = gets.to_s
line = client.gets
puts line.chop
end
server.close
Client:
require 'socket' # Sockets are in standard library
hostname = 'localhost'
port = 8080
s = TCPSocket.open(hostname, port)
s1 = gets.to_s
s.puts(s1)
end
s.close
ClientAdd:
hostname = 'localhost'
port = 8080
s = TCPSocket.open(hostname, port)
s2 = gets.to_s
s.puts(s2)
end
ch = gets.to_i
s.puts(ch)
s.close
ServerAdd:
require 'socket' # Get sockets from stdlib
sum=0
mul=1
for i in 0..3
mul=mul*line.to_i
end
line=client.gets
if line.to_i == 1
client.puts(sum)
else
client.puts(mul)
end
client.puts("000")
server.close