Skip to content

Instantly share code, notes, and snippets.

@jonathanBieler
Created April 2, 2018 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathanBieler/7d3460b72dd4bd1d2c192ad3bdccec3a to your computer and use it in GitHub Desktop.
Save jonathanBieler/7d3460b72dd4bd1d2c192ad3bdccec3a to your computer and use it in GitHub Desktop.
RemoteEval
module RemoteEval
@enum Messages DONE=1
function start_server()
port, server = listenany(8000)
@async begin
while true
sock = accept(server)
@async while isopen(sock)
data = deserialize(sock)
response = process_message_server(data)
serialize(sock, response)
end
end
end
port, server
end
function process_message_server(data)
println(data)
DONE
end
function process_message_server(data::Tuple{Module,Expr})
eval(data...)
end
function remote_eval(client, mod::Module, ex::Expr)
serialize(client, (mod, ex) )
deserialize(client)
end
end # module
port, server = RemoteEval.start_server()
client = connect(port)
serialize(client,"test")
deserialize(client)
RemoteEval.remote_eval(client,Main,:(x=rand(19)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment