Sha256: 4ffeed6e14f9f11b2446e7e399552b8a9c77d9b491e3b293ecc0fde43a20cd52

Contents?: true

Size: 796 Bytes

Versions: 19

Compression:

Stored size: 796 Bytes

Contents

#!/usr/bin/env ruby

$LOAD_PATH << File.expand_path("../../lib", __dir__)

require 'async/reactor'
require 'async/io/stream'
require 'async/io/host_endpoint'
require 'async/io/protocol/line'

class User < Async::IO::Protocol::Line
end

endpoint = Async::IO::Endpoint.parse(ARGV.pop || "tcp://localhost:7138")

input = Async::IO::Protocol::Line.new(
	Async::IO::Stream.new(
		Async::IO::Generic.new($stdin)
	)
)

Async::Reactor.run do |task|
	socket = endpoint.connect
	stream = Async::IO::Stream.new(socket)
	user = User.new(stream)
	
	connection = task.async do
		while line = user.read_line
			puts line
		end
	end
	
	while line = input.read_line
		user.write_lines line
	end
rescue EOFError
	# It's okay, we are disconnecting, because stdin has closed.
ensure
	connection.stop
	user.close
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
async-io-1.18.2 examples/chat/client.rb
async-io-1.18.1 examples/chat/client.rb
async-io-1.17.2 examples/chat/client.rb
async-io-1.17.1 examples/chat/client.rb
async-io-1.16.4 examples/chat/client.rb
async-io-1.16.3 examples/chat/client.rb
async-io-1.16.2 examples/chat/client.rb
async-io-1.16.1 examples/chat/client.rb
async-io-1.16.0 examples/chat/client.rb
async-io-1.15.5 examples/chat/client.rb
async-io-1.15.4 examples/chat/client.rb
async-io-1.15.3 examples/chat/client.rb
async-io-1.15.2 examples/chat/client.rb
async-io-1.15.1 examples/chat/client.rb
async-io-1.15.0 examples/chat/client.rb
async-io-1.14.0 examples/chat/client.rb
async-io-1.13.0 examples/chat/client.rb
async-io-1.12.3 examples/chat/client.rb
async-io-1.12.2 examples/chat/client.rb