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.45.0 examples/io/xx-echo_server_with_timeout.rb
polyphony-0.44.0 examples/io/xx-echo_server_with_timeout.rb
polyphony-0.43.11 examples/io/xx-echo_server_with_timeout.rb
polyphony-0.43.10 examples/io/xx-echo_server_with_timeout.rb
polyphony-0.43.9 examples/io/xx-echo_server_with_timeout.rb
polyphony-0.43.8 examples/io/xx-echo_server_with_timeout.rb
polyphony-0.43.6 examples/io/xx-echo_server_with_timeout.rb
polyphony-0.43.5 examples/io/xx-echo_server_with_timeout.rb
polyphony-0.43.4 examples/io/xx-echo_server_with_timeout.rb
polyphony-0.43.3 examples/io/xx-echo_server_with_timeout.rb
polyphony-0.43.2 examples/io/xx-echo_server_with_timeout.rb
polyphony-0.43.1 examples/io/xx-echo_server_with_timeout.rb
polyphony-0.43 examples/io/xx-echo_server_with_timeout.rb
polyphony-0.42 examples/io/xx-echo_server_with_timeout.rb
polyphony-0.41 examples/io/xx-echo_server_with_timeout.rb
polyphony-0.40 examples/io/xx-echo_server_with_timeout.rb
polyphony-0.39 examples/io/xx-echo_server_with_timeout.rb
polyphony-0.38 examples/io/xx-echo_server_with_timeout.rb
polyphony-0.36 examples/io/xx-echo_server_with_timeout.rb
polyphony-0.34 examples/io/xx-echo_server_with_timeout.rb