-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aaa6b20
commit f576d4d
Showing
3 changed files
with
86 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
|
||
<p id="status">?</p> | ||
|
||
<button type="button" onclick="sayhello()">Say "Hello" to Julia</button> | ||
|
||
<script> | ||
|
||
var href = window.location.href; | ||
var sock = new WebSocket("ws"+href.substr(4,href.length)); | ||
sock.onmessage = function( message ){ | ||
var msg = message.data; | ||
document.getElementById("status").innerHTML = msg | ||
console.log(msg); | ||
} | ||
|
||
sock.onopen = function () { | ||
sock.send("Hello Julia! From JavaScript") | ||
}; | ||
|
||
window.onbeforeunload = function() { | ||
sock.onclose = function () {}; | ||
sock.close() | ||
}; | ||
|
||
var count = 1 | ||
|
||
function sayhello() { | ||
sock.send("Hello Julia! From JavaScript " + count) | ||
count = count + 1 | ||
} | ||
|
||
</script> | ||
|
||
</body> | ||
</html> |
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,41 @@ | ||
using HTTP | ||
using HTTP: hasheader | ||
|
||
@static if is_apple() | ||
launch(x) = run(`open $x`) | ||
elseif is_linux() | ||
launch(x) = run(`xdg-open $x`) | ||
elseif is_windows() | ||
launch(x) = run(`cmd /C start $x`) | ||
end | ||
|
||
@async begin | ||
sleep(2) | ||
launch("http://127.0.0.1:8000/examples/mwe") | ||
end | ||
|
||
HTTP.listen(ip"127.0.0.1",8000) do http | ||
@show http | ||
if http.message.method == "GET" && | ||
hasheader(http, "Connection", "upgrade") && | ||
hasheader(http, "Upgrade", "websocket") | ||
|
||
HTTP.WebSockets.upgrade(http) do client | ||
count = 1 | ||
while !eof(client); | ||
msg = String(readavailable(client)) | ||
println(msg) | ||
write(client, "Hello JavaScript! From Julia $count") | ||
count += 1 | ||
end | ||
end | ||
else | ||
HTTP.Servers.handle_request(http) do req::HTTP.Request | ||
HTTP.Response(200,readstring(joinpath(dirname(@__FILE__),"mwe.html"))) | ||
end | ||
end | ||
end | ||
|
||
|
||
|
||
|