Skip to content

Commit

Permalink
Added Ronin::Support::Web::WebSocket (closes #5).
Browse files Browse the repository at this point in the history
* Added `Ronin::Support::Web::WebSocket::Client`.
* Added `Ronin::Support::Web::WebSocket::Server`.
* Added `Ronin::Support::Web::WebSocket::Mixin`.
  • Loading branch information
postmodern committed Jan 18, 2024
1 parent ff6d595 commit bc04dda
Show file tree
Hide file tree
Showing 13 changed files with 3,165 additions and 0 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ provides many helper methods for parsing HTML/XML, fetching web pages, etc.
* Provides helper methods for parsing HTML/XML.
* Also provides additional extensions to [Nokogiri][nokogiri] using
[nokogiri-ext].
* Provides helper methods for working with WebSockets.

## Examples

Expand Down Expand Up @@ -222,6 +223,39 @@ post_json 'https://example.com/api/endpoint.json', json: {foo: 'bar'}
# => {...}
```

### WebSockets

Connecting to a WebSocket:

```ruby
websocket = websocket_connect('ws://websocket-echo.com')

websocket.send_frame("foo bar")
# => 13
websocket.recv_frame
# => <WebSocket::Frame::Incoming::Client:0x000227a4 @decoded=true, @code=nil, @data="foo bar", @version=13, @handler=#<WebSocket::Frame::Handler::Handler07:0x00007f7d4c9b0ed0 @frame=<WebSocket::Frame::Incoming::Client:0x000227a4 @decoded=true, @code=nil, @data="foo bar", @version=13, @handler=#<WebSocket::Frame::Handler::Handler07:0x00007f7d4c9b0ed0 ...>, @type=:text>, @application_data_buffer=nil>, @type=:text>
websocket.send_frame("hello world")
# => 17
websocket.recv
# => "hello world"
```

Starting a WebSocket server and receiving connections:

```ruby
server = websocket_server('ws://localhost:1337/')
client = server.accept
client.send("hello")
client.recv
# => "good, how are you"
```
```ruby
client = websocket_client('ws://localhost:1337/')
client.recv
# => "hello"
client.send("good, how are you")
```

## Requirements

* [Ruby] >= 3.0.0
Expand Down
2 changes: 2 additions & 0 deletions lib/ronin/support/web/mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
require 'ronin/support/web/html/mixin'
require 'ronin/support/web/xml/mixin'
require 'ronin/support/web/agent/mixin'
require 'ronin/support/web/websocket/mixin'

module Ronin
module Support
Expand All @@ -29,6 +30,7 @@ module Mixin
include HTML::Mixin
include XML::Mixin
include Agent::Mixin
include WebSocket::Mixin
end
end
end
Expand Down
Loading

0 comments on commit bc04dda

Please sign in to comment.