-
-
Save zamith/66536e2b3fad68aa8cf9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var connection = new WebSocket('ws://127.0.0.1:3000') | |
connection.send("Hello World from WS") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "http/server" | |
handler = ->(request : HTTP::Request) do | |
HTTP::Response.ok("text/plain", "ok\n") | |
end | |
middleware = HTTP::Server.build_middleware [ | |
HTTP::LogHandler.new, | |
HTTP::ErrorHandler.new, | |
HTTP::WebSocketHandler.new do |ws| | |
ws.onmessage do |data| | |
puts data | |
end | |
end | |
], handler | |
server = HTTP::Server.new(3000, middleware) | |
server.listen |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment