Websocket Example

158 views
Skip to first unread message

Keenan Brock

unread,
Aug 29, 2015, 12:45:23 AM8/29/15
to Crystal
Hi All,

Most of the definitions of Crystal mention websockets in the standard library.

Does anyone have a chat room example on github using websockets?

Thanks,
Keenan

Ary Borenszweig

unread,
Sep 2, 2015, 3:33:19 PM9/2/15
to crysta...@googlegroups.com
Here's the simplest websocket example:

~~~
require "http"

websocket_handler = HTTP::WebSocketHandler.new do |session|
  puts "New session!"
  session.on_message do |message|
    session.send "Echo: #{message}"
  end
end

server = HTTP::Server.new(8080, websocket_handler)
puts "Listening on port 8080"
server.listen
~~~

I'm not sure, but I think the above only compiles in HEAD, websocket has gone through some improvements.


--
You received this message because you are subscribed to the Google Groups "Crystal" group.
To unsubscribe from this group and stop receiving emails from it, send an email to crystal-lang...@googlegroups.com.
To post to this group, send email to crysta...@googlegroups.com.
Visit this group at http://groups.google.com/group/crystal-lang.
To view this discussion on the web visit https://groups.google.com/d/msgid/crystal-lang/f41afae4-8172-4bd4-a42e-bcb4849900d7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Ary Borenszweig         Manas Technology Solutions
[ar.phone]                      5258.5240       #ARY(279)
[us.phone]                      312.612.1050    #ARY(279)
[email]                         aboren...@manas.com.ar
[web]                           www.manas.com.ar
Reply all
Reply to author
Forward
0 new messages