-
-
Save vschiavoni/7829c716bbd60096de5f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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 |
This file contains hidden or 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
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 |
This file contains hidden or 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
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) |
This file contains hidden or 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
-- 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) |
This file contains hidden or 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
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) |
This file contains hidden or 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
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) |
This file contains hidden or 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
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