Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
shashi authored May 15, 2017
2 parents 9bd583b + 18a88a0 commit 7ffa0a7
Show file tree
Hide file tree
Showing 9 changed files with 329 additions and 268 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ WebSockets.jl
[![Build Status](https://travis-ci.org/JuliaWeb/WebSockets.jl.png)](https://travis-ci.org/JuliaWeb/WebSockets.jl)
[![Coverage Status](https://img.shields.io/coveralls/JuliaWeb/WebSockets.jl.svg)](https://coveralls.io/r/JuliaWeb/WebSockets.jl)

[![WebSockets](http://pkg.julialang.org/badges/WebSockets_0.3.svg)](http://pkg.julialang.org/?pkg=WebSockets&ver=0.3)
[![WebSockets](http://pkg.julialang.org/badges/WebSockets_0.4.svg)](http://pkg.julialang.org/?pkg=WebSockets&ver=0.4)
[![WebSockets](http://pkg.julialang.org/badges/WebSockets_0.5.svg)](http://pkg.julialang.org/?pkg=WebSockets&ver=0.5)
[![WebSockets](http://pkg.julialang.org/badges/WebSockets_0.6.svg)](http://pkg.julialang.org/?pkg=WebSockets&ver=0.6)

This is a server-side implementation of the WebSockets protocol in Julia. If you want to write a web app in Julia that uses WebSockets, you'll need this package.

Expand Down
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
julia 0.4
Compat 0.7.16
Compat 0.9.5
HttpCommon 0.0.3
HttpServer 0.0.4
Codecs
Expand Down
36 changes: 36 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
environment:
matrix:
- JULIAVERSION: "julialang/bin/winnt/x86/0.4/julia-0.4-latest-win32.exe"
- JULIAVERSION: "julialang/bin/winnt/x64/0.4/julia-0.4-latest-win64.exe"
- JULIAVERSION: "julialang/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe"
- JULIAVERSION: "julialang/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe"
- JULIAVERSION: "julianightlies/bin/winnt/x86/julia-latest-win32.exe"
- JULIAVERSION: "julianightlies/bin/winnt/x64/julia-latest-win64.exe"

branches:
only:
- master
- /release-.*/

notifications:
- provider: Email
on_build_success: false
on_build_failure: false
on_build_status_changed: false

install:
# Download most recent Julia Windows binary
- ps: (new-object net.webclient).DownloadFile(
$("http://s3.amazonaws.com/"+$env:JULIAVERSION),
"C:\projects\julia-binary.exe")
# Run installer silently, output to C:\projects\julia
- C:\projects\julia-binary.exe /S /D=C:\projects\julia

build_script:
# Need to convert from shallow to complete for Pkg.clone to work
- IF EXIST .git\shallow (git fetch --unshallow)
- C:\projects\julia\bin\julia -e "versioninfo();
Pkg.clone(pwd(), \"WebSockets\"); Pkg.build(\"WebSockets\")"

test_script:
- C:\projects\julia\bin\julia -e "Pkg.test(\"WebSockets\")"
4 changes: 2 additions & 2 deletions examples/chat-client.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ <h1>Select a username</h1>
var you = "you";
connection.onmessage = function( message ){
window.lastmessage = message;
$("#content").prepend( $("<p class='received'></p>").html( message.data ) );
$("#content").append( $("<p class='received'></p>").html( message.data ) );
}
function changeUsername( username ){
you = username;
Expand All @@ -42,7 +42,7 @@ <h1>Select a username</h1>
}
function sendMessage( message ){
connection.send('say:'+ message);
$("#content").prepend( $("<p class='sent'></p>").html( you + ": " + message ) );
$("#content").append( $("<p class='sent'></p>").html( you + ": " + message ) );
}
$("#sayer input[type=submit]").click(function(){
if( $("#sayer input[name=say]").val().replace(/\s/gi,'').length )
Expand Down
4 changes: 2 additions & 2 deletions examples/chat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ global connections = Dict{Int,WebSocket}()
global usernames = Dict{Int,String}()

function decodeMessage( msg )
bytestring(msg)
String(copy(msg))
end

wsh = WebSocketHandler() do req, client
Expand All @@ -30,7 +30,7 @@ wsh = WebSocketHandler() do req, client
end
end

onepage = readall(Pkg.dir("Websockets","examples","chat-client.html"))
onepage = readstring(Pkg.dir("WebSockets","examples","chat-client.html"))
httph = HttpHandler() do req::Request, res::Response
Response(onepage)
end
Expand Down
16 changes: 12 additions & 4 deletions examples/repl-client.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,20 @@
var you = "you";
connection.onmessage = function( message ){
window.lastmessage = message;
$("#content").prepend( $("<p class='received'></p>").html( message.data ) );
$("#content").append( $("<p class='received'></p>").html( message.data ) );
}
function sendMessage( message ){
connection.send(message);
$("#content").prepend( $("<p class='sent'></p>").html( you + ": " + message ) );
}
if(typeof connection === 'undefined' || connection === null){
$("#content").append( $("<p class='received'>Connection not defined</p>"));
} else {
if(connection.readyState==1){
connection.send(message);
$("#content").append( $("<p class='sent'></p>").html( you + ": " + message ) );
} else {
$("#content").append( $("<p class='received'>Connection not ready</p>"));
};
};
};
$("#sayer input[type=submit]").click(function(){
if( $("#sayer input[name=say]").val().replace(/\s/gi,'').length )
sendMessage( $("#sayer input[name=say]").val() );
Expand Down
23 changes: 15 additions & 8 deletions examples/server.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,36 @@ global connections = Dict{Int,WebSocket}()
global usernames = Dict{Int,String}()

function decodeMessage( msg )
bytestring(msg)
String(copy(msg))
end

function eval_or_describe_error(strmsg)
try
return eval(parse(strmsg, raise = false))
catch err
iob = IOBuffer()
dump(iob, err)
return String(take!(iob))
end
end

wsh = WebSocketHandler() do req, client
global connections
connections[client.id] = client
while true
msg = read(client)
msg = decodeMessage(msg)
val = eval(parse(msg))
output = takebuf_string(Base.mystreamvar)
val = client |> read |> decodeMessage |> eval_or_describe_error
output = String(take!(Base.mystreamvar))
val = val == nothing ? "<br>" : val
write(client,"$val<br>$output")
end
end

onepage = readall(Pkg.dir("WebSockets","examples","repl-client.html"))
onepage = readstring(Pkg.dir("WebSockets","examples","repl-client.html"))
httph = HttpHandler() do req::Request, res::Response
Response(onepage)
end

server = Server(httph, wsh)
println("Chat server listening on 8080...")
println("Repl server listening on 8080...")

eval(Base,parse("mystreamvar = IOBuffer()"))
eval(Base,parse("STDOUT = mystreamvar"))
Expand Down
Loading

0 comments on commit 7ffa0a7

Please sign in to comment.