diff --git a/examples/rack/client.rb b/examples/rack/client.rb index 8e2953c..c9c94cc 100755 --- a/examples/rack/client.rb +++ b/examples/rack/client.rb @@ -14,11 +14,11 @@ endpoint = Async::HTTP::Endpoint.parse(URL) Async::WebSocket::Client.connect(endpoint) do |connection| - connection.send_text("Hello World") - connection.flush + 1000.times do + connection.send_text("Hello World") + connection.flush - while message = connection.read - p message + puts connection.read end end end diff --git a/examples/rack/gems.locked b/examples/rack/gems.locked index 1f0eed4..6de5a36 100644 --- a/examples/rack/gems.locked +++ b/examples/rack/gems.locked @@ -1,95 +1,95 @@ PATH remote: ../.. specs: - async-websocket (0.22.0) + async-websocket (0.26.1) async-http (~> 0.54) - async-io (~> 1.23) - protocol-rack (~> 0.1.1) - protocol-websocket (~> 0.9.1) - -PATH - remote: /Users/samuel/Projects/socketry/protocol-rack - specs: - protocol-rack (0.1.5) - protocol-http (~> 0.23.4) - rack (>= 1.0) + protocol-rack (~> 0.5) + protocol-websocket (~> 0.14) GEM remote: https://rubygems.org/ specs: - async (2.0.3) - console (~> 1.10) - io-event (~> 1.0.0) - timers (~> 4.1) - async-container (0.16.12) - async - async-io - async-http (0.59.1) - async (>= 1.25) - async-io (>= 1.28) - async-pool (>= 0.2) - protocol-http (~> 0.23.1) - protocol-http1 (~> 0.14.0) - protocol-http2 (~> 0.14.0) - traces (>= 0.4.0) - async-http-cache (0.4.2) + async (2.12.0) + console (~> 1.25, >= 1.25.2) + fiber-annotation + io-event (~> 1.6) + async-container (0.18.2) + async (~> 2.10) + async-http (0.67.1) + async (>= 2.10.2) + async-pool (>= 0.6.1) + io-endpoint (~> 0.10, >= 0.10.3) + io-stream (~> 0.4) + protocol-http (~> 0.26.0) + protocol-http1 (~> 0.19.0) + protocol-http2 (~> 0.18.0) + traces (>= 0.10.0) + async-http-cache (0.4.3) async-http (~> 0.56) - async-io (1.33.0) - async - async-pool (0.3.11) + async-pool (0.6.1) async (>= 1.25) - build-environment (1.13.0) - console (1.15.3) - fiber-local - falcon (0.42.2) + async-service (0.12.0) + async + async-container (~> 0.16) + console (1.25.2) + fiber-annotation + fiber-local (~> 1.1) + json + falcon (0.47.6) async - async-container (~> 0.16.0) - async-http (~> 0.57) + async-container (~> 0.18) + async-http (~> 0.66, >= 0.66.3) async-http-cache (~> 0.4.0) - async-io (~> 1.22) - build-environment (~> 1.13) + async-service (~> 0.10) bundler localhost (~> 1.1) openssl (~> 3.0) process-metrics (~> 0.2.0) - protocol-rack (~> 0.1.4) - samovar (~> 2.1) - fiber-local (1.0.0) - io-event (1.0.9) - localhost (1.1.9) + protocol-rack (~> 0.5) + samovar (~> 2.3) + fiber-annotation (0.2.0) + fiber-local (1.1.0) + fiber-storage + fiber-storage (0.1.2) + io-endpoint (0.10.3) + io-event (1.6.4) + io-stream (0.4.0) + json (2.7.2) + localhost (1.3.1) mapping (1.1.1) - nio4r (2.5.8) - openssl (3.0.0) + nio4r (2.7.3) + openssl (3.2.0) process-metrics (0.2.1) console (~> 1.8) samovar (~> 2.1) - protocol-hpack (1.4.2) - protocol-http (0.23.5) - protocol-http1 (0.14.4) + protocol-hpack (1.4.3) + protocol-http (0.26.5) + protocol-http1 (0.19.1) protocol-http (~> 0.22) - protocol-http2 (0.14.2) + protocol-http2 (0.18.0) protocol-hpack (~> 1.4) protocol-http (~> 0.18) - protocol-websocket (0.9.1) + protocol-rack (0.6.0) + protocol-http (~> 0.23) + rack (>= 1.0) + protocol-websocket (0.14.0) protocol-http (~> 0.2) - protocol-http1 (~> 0.2) - puma (5.6.4) + puma (6.4.2) nio4r (~> 2.0) - rack (2.2.4) - samovar (2.1.4) + rack (3.1.3) + samovar (2.3.0) console (~> 1.0) mapping (~> 1.0) - timers (4.3.3) - traces (0.6.1) + traces (0.11.1) PLATFORMS arm64-darwin-21 + arm64-darwin-23 DEPENDENCIES async-websocket! falcon - protocol-rack! puma BUNDLED WITH - 2.3.10 + 2.5.9 diff --git a/examples/rack/gems.rb b/examples/rack/gems.rb index 02cd08a..f6f5fbd 100644 --- a/examples/rack/gems.rb +++ b/examples/rack/gems.rb @@ -7,6 +7,4 @@ gem "puma" gem "falcon" - gem "async-websocket", path: "../../" -gem "protocol-rack" diff --git a/examples/rack/readme.md b/examples/rack/readme.md new file mode 100644 index 0000000..fe703ba --- /dev/null +++ b/examples/rack/readme.md @@ -0,0 +1,33 @@ +# Rack Example + +This example shows how to host a WebSocket server using Rack. + +## Usage + +Install the dependencies: + +~~~ bash +$ bundle update +~~~ + +Then start the server: + +~~~ bash +$ bundle exec falcon serve --bind "http://localhost:9292" +~~~ + +You can connect to the server using a WebSocket client: + +~~~ bash +$ bundle exec ./client.rb "http://localhost:9292" +~~~ + +### Using Puma + +You can also use Puma to host the server: + +~~~ bash +$ bundle exec puma --bind "tcp://localhost:9292" +~~~ + +The command for running the client is the same.