Sha256: ea71bedfaeeff944961f034370fb393dc47f51d941748fa44eca32db17875c19
Contents?: true
Size: 772 Bytes
Versions: 6
Compression:
Stored size: 772 Bytes
Contents
#!/usr/bin/env ruby require 'async' reactor = Async::Reactor.new puts "Creating server" server = TCPServer.new("localhost", 6777) REPEATS = 10 timer = reactor.after(1) do puts "Reactor timed out!" reactor.stop end reactor.async(server) do |server, task| REPEATS.times do |i| puts "Accepting peer on server #{server}" task.with(server.accept) do |peer| puts "Sending data to peer" peer << "data #{i}" peer.shutdown end end puts "Server finished, canceling timer" timer.cancel end REPEATS.times do |i| # This aspect of the connection is synchronous. puts "Creating client #{i}" client = TCPSocket.new("localhost", 6777) reactor.async(client) do |client| puts "Reading data on client #{i}" puts client.read(1024) end end reactor.run
Version data entries
6 entries across 6 versions & 1 rubygems
Version | Path |
---|---|
async-0.13.0 | examples/aio.rb |
async-0.12.0 | examples/aio.rb |
async-0.11.1 | examples/aio.rb |
async-0.11.0 | examples/aio.rb |
async-0.10.0 | examples/aio.rb |
async-0.9.1 | examples/aio.rb |