-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mod:: README.md Add 'Errors?', 'Switch to HTTP' mod:: benchmark/benchmark.jl Include benchmark_prepare.jl mod:: benchmark/benchmark_prepare.jl Avoid redefinitions mod:: benchmark/functions_open_browsers.jl Mutable default address mod:: examples/chat_explore.jl usews(ws) -> coroutine(ws) new: examples/minimal_server.jl Readme.md example new: examples/minimal_server_HTTP.jl Readme.md example for HTTP deleted: examples/repl-client.html Delete bad practice deleted: examples/server.jl Delete insecure practice: eval. mod:: src/HTTP.jl Add methods for serve, fewer arguments. mod:: test/client_server_test.jl Use fewer arguments mod:: test/error_test.jl Use new methods serve
- Loading branch information
Showing
12 changed files
with
157 additions
and
143 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using HttpServer | ||
using WebSockets | ||
|
||
function coroutine(ws) | ||
while isopen(ws) | ||
data, = readguarded(ws) | ||
s = String(data) | ||
if s == "" | ||
break | ||
end | ||
println(s) | ||
if s[1] == "P" | ||
writeguarded(ws, "No, I'm not!") | ||
else | ||
writeguarded(ws, "Why?") | ||
end | ||
end | ||
end | ||
|
||
function gatekeeper(req, ws) | ||
if origin(req) == "http://127.0.0.1:8080" || origin(req) == "http://localhost:8080" | ||
coroutine(ws) | ||
else | ||
println(origin(req)) | ||
end | ||
end | ||
|
||
handle(req, res) = Response(200) | ||
|
||
server = Server(HttpHandler(handle), | ||
WebSocketHandler(gatekeeper)) | ||
|
||
@async run(server, 8080) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using HTTP | ||
using WebSockets | ||
|
||
function coroutine(ws) | ||
while isopen(ws) | ||
data, = readguarded(ws) | ||
s = String(data) | ||
if s == "" | ||
break | ||
end | ||
println(s) | ||
if s[1] == "P" | ||
writeguarded(ws, "No, I'm not!") | ||
else | ||
writeguarded(ws, "Why?") | ||
end | ||
end | ||
end | ||
|
||
function gatekeeper(req, ws) | ||
if origin(req) == "http://127.0.0.1:8080" || origin(req) == "http://localhost:8080" | ||
coroutine(ws) | ||
else | ||
println(origin(req)) | ||
end | ||
end | ||
|
||
handle(req, res) = HTTP.Response(200) | ||
|
||
server = WebSockets.ServerWS(HTTP.HandlerFunction(handle), | ||
WebSockets.WebsocketHandler(gatekeeper)) | ||
|
||
@async WebSockets.serve(server, 8080) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.