Skip to content

Instantly share code, notes, and snippets.

@ralucah
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ralucah/12de4eca26739ff13ad5 to your computer and use it in GitHub Desktop.
Save ralucah/12de4eca26739ff13ad5 to your computer and use it in GitHub Desktop.
local host, port = "10.0.13.3", 20000
local socket = require("socket")
client = socket.tcp()
client:settimeout(100)
client:connect(host, port)
payload=string.rep("a",16*1024*1024)
payload=payload.."\n"
--print(payload)
for i=1,10 do
t0=socket.gettime()*1000
ok,err = client:send(payload)
t1=socket.gettime()*1000
print(i,t1-t0,"ms")
ok,err = client:receive("*l")
print(ok)
end
socket=require"socket.core"
local s, err = socket.tcp()
s:bind("*",20000)
s:listen()
cs,err=s:accept()
print(err)
cs:settimeout(100)
while true do
local t1 = socket.gettime()*1000
local x,err = cs:receive()
local t2 = socket.gettime()*1000
print((t2 - t1).." ms")
if x then
--print(string.len(x))
else
--print("Error is: "..err)
os.exit()
end
cs:send("ok\n")
end
require("splay.base")
misc = require("splay.misc")
rpc = require("splay.rpc")
--rpc = require("splay.rpcq")
me = {ip = "10.0.13.2", port = 20000}
you = {ip = "10.0.13.3", port = 20000}
rpc.server(me)
events.run(function()
piggy = string.rep('a',16*1024*1024)
for i=1,10 do
t1 = misc.time()
ok, err = rpc.call(you, {"call_me", piggy})
t2 = misc.time()
print(((t2 - t1) * 1000).." ms")
end
end)
-- periodically sends RPCs (with a small payload) to the server
require("splay.base")
misc = require("splay.misc")
-- rpc or rpcq
rpc = require("splay.rpc")
--rpc = require("splay.rpcq")
me = {ip = "10.0.13.4", port = 20000}
you = {ip = "10.0.13.3", port = 20000}
rpc.server(me)
events.run(function()
for i=1,1000 do
ok, err = rpc.call(you, {"ping_me", "ping"})
events.sleep(0.5)--0.05
end
end)
require("splay.base")
-- rpc or rpcq
rpc = require("splay.rpc")
--rpc = require("splay.rpcq")
me = {ip = "10.0.13.3", port = 20000}
rpc.server(me)
function ping_me(ping)
return true
end
function call_me(a)
--print("function was called on server")
--return "Server says: You called me with "..string.len(a)
end
events.run(function()
print("Waiting for rpc...")
end)
require"splay.base"
net=require"splay.net"
function tcp_upload(s)
t0=socket.gettime()*1000
payload = ""
payload = string.rep("a",16*1024*1024)
payload = payload.."\n"
for i=1,10 do
print("payload len: "..string.len(payload))
ok,err = s:send(payload)
if err then print(err) end
end
t1=socket.gettime()*1000
print(i,t1-t0,"ms")
end
events.run(function()
local host, port = "10.0.13.3", 20000
dest={ip=host,port=port}
net.client(dest,{send=tcp_upload})
events.sleep(100)
events.exit()
end)
require("splay.base")
net = require("splay.net")
require("splay.misc")
function server_callback(s)
for i=1,10 do
local t1= socket.gettime()*1000
local ok, err = s:receive("*l")
local t2 = socket.gettime()*1000
print((t2 - t1).."ms")
end
if not err then
--print(string.len(ok))
else
print(err)
end
end
events.run(function()
net.server(20000, server_callback)
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment