From 40b8411f2595fb7e5f24e8d7a9087ae84f4a4e49 Mon Sep 17 00:00:00 2001 From: Sdogruyol Date: Wed, 16 Dec 2015 20:21:17 +0200 Subject: [PATCH] Format websocket doc --- docs/websockets.md | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/docs/websockets.md b/docs/websockets.md index 630505c..14a9bef 100644 --- a/docs/websockets.md +++ b/docs/websockets.md @@ -6,30 +6,31 @@ You can easily create a websocket handler which matches the route of `ws://host: with different routes. ```ruby - ws "/" do |socket| +ws "/" do |socket| - end +end - ws "/route2" do |socket| +ws "/route2" do |socket| - end +end ``` Let's access the socket and create a simple echo server. ```ruby - ws "/" do |socket| - # Send welcome message to the client - socket.send "Hello from Kemal!" +# Matches "/" +ws "/" do |socket| + # Send welcome message to the client + socket.send "Hello from Kemal!" - # Handle incoming message and echo back to the client - socket.on_message do |message| - socket.send "Echo back from server #{message}" - end - - # Executes when the client is disconnected. You can do the cleaning up here. - socket.on_close do - puts "Closing socket" - end + # Handle incoming message and echo back to the client + socket.on_message do |message| + socket.send "Echo back from server #{message}" end + + # Executes when the client is disconnected. You can do the cleaning up here. + socket.on_close do + puts "Closing socket" + end +end ```