Created
March 14, 2013 23:38
-
-
Save astrieanna/5166251 to your computer and use it in GitHub Desktop.
Socket code in Julia.
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
echo2_helper(socket,stat) = | |
begin | |
println(stat) | |
show(socket) | |
c = accept(socket) | |
println(c) | |
line = read_line(c) | |
println(line) | |
while line != "0\n" | |
write(c,line) | |
line = read_line(c) | |
end | |
close(c) | |
end | |
echo2(port::Int) = | |
begin | |
socket = listen(port) | |
socket.ccb = echo2_helper | |
end |
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
julia> echo2(8000) | |
# methods for generic function echo2_helper | |
echo2_helper(socket,stat) at /home/leah/code/julia-websocket-server/websockets.jl:12 | |
julia> 0 | |
TcpSocket(connected,0 bytes waiting)ERROR: MemoryError() | |
in push! at array.jl:653 | |
in wait at stream.jl:131 | |
in readline at stream.jl:380 | |
in echo2_helper at /home/leah/code/julia-websocket-server/websockets.jl:18 | |
in _uv_hook_connectioncb at stream.jl:159 | |
in event_loop at multi.jl:1386 | |
in anonymous at client.jl:281ERROR: in tasknotify: work not defined | |
in tasknotify at stream.jl:104 | |
in _uv_hook_readcb at stream.jl:208 | |
in event_loop at multi.jl:1386 | |
in anonymous at client.jl:281ERROR: in tasknotify: work not defined | |
in tasknotify at stream.jl:104 | |
in _uv_hook_readcb at stream.jl:208 | |
in event_loop at multi.jl:1386 | |
in anonymous at client.jl:281 |
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
echo(client) = (args...) -> begin | |
line = readline(client) | |
write(client,line) | |
if line != "0\n" | |
return true | |
end | |
close(client) | |
false | |
end | |
echo_server(port::Int) = | |
listen(port) do sock,stat | |
client = accept(sock) | |
client.readcb = echo(client) | |
start_reading(client) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment