Closed yfractal closed 6 years ago
Thanks for your report. Okay I will check. I've been pretty busy with this code base the past few days, things are converging on a 1.0 release. It would be good to have some more examples.
Okay, here is the working example. I'll check with what's in the readme, but the original code has some issues.
#!/usr/bin/env ruby
require 'async/reactor'
require 'async/http/client'
require 'async/http/server'
require 'async/http/url_endpoint'
class Server < Async::HTTP::Server
def handle_request(request, peer, address)
[200, {}, ["Hello World"]]
end
end
endpoint = Async::IO::Endpoint.tcp('127.0.0.1', 9294, reuse_port: true)
client_endpoint = Async::HTTP::URLEndpoint.parse("http://127.0.0.1:9294", reuse_port: true)
server = Server.new(endpoint)
client = Async::HTTP::Client.new(client_endpoint)
Async::Reactor.run do |task|
server_task = task.async do
server.run
end
response = client.get("/", {})
puts response.read
server_task.stop
end
Okay I've updated the README example and it's working well.
Sorry, just notice your comments ...
Yeah, it works! Thank you. The async-*
gems look great 👍
I run code as below:
But get error:
ERROR -- : Connection refused - connect(2) for [::1]:80:
The
Async::IO::VERSION
is "1.6.1"I use
Async::HTTP::URLEndpoint.parse
to get client endpoint becauseAsync::HTTP::Client
needsendpoint
hasprotocol
method.