File tree Expand file tree Collapse file tree 1 file changed +38
-3
lines changed Expand file tree Collapse file tree 1 file changed +38
-3
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,44 @@ Or install it yourself as:
22
22
23
23
## Usage
24
24
25
- Here is how to use within ` Rack ` :
25
+ There are [ examples] ( examples/ ) which include:
26
+
27
+ - [ A command line chat client and application server] ( examples/chat/client.rb ) which can read input from ` stdin ` and send messages to the server.
28
+ - [ A utopia-based web application] ( examples/utopia ) which uses a JavaScript client to connect to a web application server.
29
+
30
+ ### Client Side with Async
31
+
32
+ ``` ruby
33
+ # !/usr/bin/env ruby
34
+
35
+ require ' async'
36
+ require ' async/io/stream'
37
+ require ' async/http/url_endpoint'
38
+ require ' async/websocket/client'
39
+
40
+ USER = ARGV .pop || " anonymous"
41
+ URL = ARGV .pop || " ws://localhost:9292"
42
+
43
+ Async do |task |
44
+ endpoint = Async ::HTTP ::URLEndpoint .parse(URL )
45
+ headers = {' token' => ' wubalubadubdub' }
46
+
47
+ endpoint.connect do |socket |
48
+ connection = Async ::WebSocket ::Client .new (socket, URL , headers)
49
+
50
+ connection.send_message({
51
+ user: USER ,
52
+ status: " connected" ,
53
+ })
54
+
55
+ while message = connection.next_message
56
+ puts message.inspect
57
+ end
58
+ end
59
+ end
60
+ ```
61
+
62
+ ### Server Side with Rack & Falcon
26
63
27
64
``` ruby
28
65
# !/usr/bin/env falcon serve --concurrency 1 -c
@@ -46,8 +83,6 @@ run lambda {|env|
46
83
}
47
84
```
48
85
49
- And [ here is a client program] ( examples/chat/client.rb ) which can read input from ` stdin ` and send messages to the server.
50
-
51
86
## Contributing
52
87
53
88
1 . Fork it
You can’t perform that action at this time.
0 commit comments