update network test
This commit is contained in:
parent
99940da426
commit
3d07507fa6
@ -1,4 +1,5 @@
|
|||||||
for i=1,3 do
|
for i=1,3 do
|
||||||
|
print(string.format("iteration %s", i + 1))
|
||||||
local text = ""
|
local text = ""
|
||||||
local complete = false
|
local complete = false
|
||||||
|
|
||||||
@ -7,32 +8,38 @@ for i=1,3 do
|
|||||||
end
|
end
|
||||||
|
|
||||||
local server = network.tcp_open(7645, function (client)
|
local server = network.tcp_open(7645, function (client)
|
||||||
|
print("client connected")
|
||||||
start_coroutine(function()
|
start_coroutine(function()
|
||||||
|
print("client-listener started")
|
||||||
local received_text = ""
|
local received_text = ""
|
||||||
while client:is_alive() do
|
while client:is_alive() and #received_text < #text do
|
||||||
local received = client:recv(512)
|
local received = client:recv(512)
|
||||||
if received then
|
if received then
|
||||||
received_text = received_text .. utf8.tostring(received)
|
received_text = received_text .. utf8.tostring(received)
|
||||||
|
print(string.format("received %s byte(s) from client", #received))
|
||||||
end
|
end
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
end
|
end
|
||||||
assert (received_text == text)
|
asserts.equals (text, received_text)
|
||||||
complete = true
|
complete = true
|
||||||
end, "client-listener")
|
end, "client-listener")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
network.tcp_connect("localhost", 7645, function (socket)
|
network.tcp_connect("localhost", 7645, function (socket)
|
||||||
|
print("connected to server")
|
||||||
start_coroutine(function()
|
start_coroutine(function()
|
||||||
|
print("data-sender started")
|
||||||
local ptr = 1
|
local ptr = 1
|
||||||
while ptr < #text do
|
while ptr <= #text do
|
||||||
local n = math.random(1, 20)
|
local n = math.random(1, 20)
|
||||||
socket:send(string.sub(text, ptr, ptr + n - 1))
|
socket:send(string.sub(text, ptr, ptr + n - 1))
|
||||||
|
print(string.format("sent %s byte(s) to server", n))
|
||||||
ptr = ptr + n
|
ptr = ptr + n
|
||||||
end
|
end
|
||||||
socket:close()
|
socket:close()
|
||||||
end, "data-sender")
|
end, "data-sender")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
app.sleep_until(function () return complete end)
|
app.sleep_until(function () return complete end, 1000000)
|
||||||
server:close()
|
server:close()
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user