Skip to content

Instantly share code, notes, and snippets.

@AStupidBear
Forked from amitmurthy/sock_echo.jl
Created February 1, 2017 00:16
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 AStupidBear/699cac5f06c5362d69b664dae5013009 to your computer and use it in GitHub Desktop.
Save AStupidBear/699cac5f06c5362d69b664dae5013009 to your computer and use it in GitHub Desktop.
addprocs(1)
@everywhere function echo_on_sock(s, N)
while true
try
read(s, Float64, (N,))
write(s, fill(Float64(myid()), N))
catch e
#println("closed by remote $e")
return;
end
end
end
@everywhere function server()
l = listen(10000)
while true
s=accept(l)
Base.disable_nagle(s)
N = read(s, Int64)
@async echo_on_sock(s, N)
end
end
@spawnat 2 server()
function client(N)
c = connect("localhost", 10000)
write(c, Int64(N))
Base.disable_nagle(c)
print("$N : ")
tic()
for i in 1:10^4
write(c, fill(Float64(myid()), N))
read(c, Float64, (N,))
end
t=toq()
println(t)
close(c)
end
client(1);
for i in 1:6
client(10^(i-1));
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment