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

Version Path
polyphony-0.33 examples/io/xx-echo_server_with_timeout.rb
polyphony-0.32 examples/io/xx-echo_server_with_timeout.rb
polyphony-0.31 examples/io/xx-echo_server_with_timeout.rb
polyphony-0.30 examples/io/xx-echo_server_with_timeout.rb
polyphony-0.29 examples/io/xx-echo_server_with_timeout.rb
polyphony-0.28 examples/io/xx-echo_server_with_timeout.rb
polyphony-0.27 examples/io/xx-echo_server_with_timeout.rb
polyphony-0.26 examples/io/xx-echo_server_with_timeout.rb
polyphony-0.25 examples/io/xx-echo_server_with_timeout.rb
polyphony-0.24 examples/io/xx-echo_server_with_timeout.rb
polyphony-0.23 examples/io/echo_server_with_timeout.rb