Skip to content

Instantly share code, notes, and snippets.

@Ismael-VC
Last active February 10, 2016 08:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ismael-VC/3b517d02a3e7e7a90d80 to your computer and use it in GitHub Desktop.
Save Ismael-VC/3b517d02a3e7e7a90d80 to your computer and use it in GitHub Desktop.
Julia plot server.
#!/usr/bin/env julia
port = begin
try
parse(Int, ARGS[1])
catch err
error("usage: `$ julia server.jl <port>`")
end
end
info("loading Gadfly...")
tic(); using Gadfly; toc()
info("JIT warmup...")
tic()
draw(SVG("output_0.svg", 6inch, 3inch), plot([sin, cos], 0, 25))
toc()
server = listen(port)
info("listening on port: $port")
while true
conn = accept(server)
@async begin
try
while isopen(conn)
eval(parse(readline(conn)))
end
catch err
println("Connection ended with error: $err")
end
end
end
@Ismael-VC
Copy link
Author

Usage

First run, ie:

$ julia server.jl 2000
INFO: loading Gadfly...
elapsed time: 4.467008744 seconds
INFO: JIT warmup...
elapsed time: 19.576495406 seconds
INFO: listening on port: 2000

Then on another terminal:

$ echo "draw(SVG(\"output_1.svg\", 6inch, 3inch), plot([sin, cos], 0, 25))" | nc -q0 localhost 2000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment