Sha256: 98dbb12f6c7653b7b6d3c6a74d8dc9117f30d76c553921c7670d91f9d56e6ed3
Contents?: true
Size: 567 Bytes
Versions: 17
Compression:
Stored size: 567 Bytes
Contents
# frozen_string_literal: true require 'socket' puts "Pid: #{Process.pid}" server = TCPServer.open('127.0.0.1', 1234) puts 'Echoing on port 1234...' begin while (client = server.accept) Thread.new do while (data = client.gets) # client.send("you said: #{data.chomp}!\n", 0) client.write('you said: ', data.chomp, "!\n") end rescue Errno::ECONNRESET 'Connection reset...' ensure puts "Closing client socket" client.shutdown client.close end end ensure puts "Closing server" server.close end
Version data entries
17 entries across 17 versions & 1 rubygems