Sha256: 86b01d669fa528176cade8dc37a05bb758ab24ec0253edb25fb73c52f679ab37
Contents?: true
Size: 768 Bytes
Versions: 31
Compression:
Stored size: 768 Bytes
Contents
# frozen_string_literal: true require 'bundler/setup' require 'polyphony' begin server = Polyphony::Net.tcp_listen( nil, 1234, reuse_addr: true, dont_linger: true ) puts 'listening on port 1234...' loop do client = server.accept client.write "Hi there\n" spin do move_on_after(5) do |scope| scope.when_cancelled do client.write "Disconnecting due to inactivity\n" end while (data = client.readpartial(8192)) scope.reset_timeout client.write "You said: #{data}" end end rescue StandardError => e puts "client error: #{e.inspect}" ensure client.close end end rescue Exception => e puts "uncaught exception: #{e.inspect}" server&.close end
Version data entries
31 entries across 31 versions & 1 rubygems