Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example in README does not work #3

Closed
yfractal opened this issue Apr 11, 2018 · 4 comments
Closed

Example in README does not work #3

yfractal opened this issue Apr 11, 2018 · 4 comments

Comments

@yfractal
Copy link

I run code as below:

endpoint        = Async::IO::Endpoint.tcp('127.0.0.1', 9294, reuse_port: true)
client_endpoint = Async::HTTP::URLEndpoint.parse("127.0.0.1/9294", reuse_port: true) 
server          = Server.new(endpoint)
client          = Async::HTTP::Client.new(client_endpoint)
 
class Server < Async::HTTP::Server
  def handle_request(request, peer, address)
    [200, {}, ["Hello World"]]
  end
end


Async::Reactor.run do |task|
  server_task = task.async do
    server.run
  end
  
  response = client.get("/", {})
  puts response.body
  
  server_task.stop
end

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 because Async::HTTP::Client needs endpoint has protocol method.

@ioquatix
Copy link
Member

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.

@ioquatix
Copy link
Member

ioquatix commented Apr 11, 2018

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

@ioquatix
Copy link
Member

Okay I've updated the README example and it's working well.

@yfractal
Copy link
Author

Sorry, just notice your comments ...

Yeah, it works! Thank you. The async-* gems look great 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants