VoxelEngine/dev/tests/network_tcp.lua
MihailRis 3a40162f1e
Fix udp address resolve (#624)
* тест для udp + фикс udp

* fix udp addresses resolve

* update SocketUdpConnection::connect

* update SocketUdpServer::sendTo

* update udp test

* revert

* test

* test

* test

* test

* test

* test?

* update test

* cleanup

* cleanup

* update test

* update

* revert

* cleanup

* update test

* update test

* update

* fix test

* additional error handling

* update Network.cpp

* update Network.cpp 2

* fix the test

* cleanup Network.cpp

* revert network_tcp.lua extra changes

---------

Co-authored-by: Xertis <118364459+Xertis@users.noreply.github.com>
2025-09-25 17:02:42 +03:00

46 lines
1.5 KiB
Lua

for i=1,3 do
print(string.format("iteration %s", i))
local text = ""
local complete = false
for j=1,100 do
text = text .. math.random(0, 9)
end
local server = network.tcp_open(7645, function (client)
print("client connected")
start_coroutine(function()
print("client-listener started")
local received_text = ""
while client:is_alive() and #received_text < #text do
local received = client:recv(512)
if received then
received_text = received_text .. utf8.tostring(received)
print(string.format("received %s byte(s) from client", #received))
end
coroutine.yield()
end
asserts.equals (text, received_text)
complete = true
end, "client-listener")
end)
network.tcp_connect("localhost", 7645, function (socket)
print("connected to server")
start_coroutine(function()
print("data-sender started")
local ptr = 1
while ptr <= #text do
local n = math.random(1, 20)
socket:send(string.sub(text, ptr, ptr + n - 1))
print(string.format("sent %s byte(s) to server", n))
ptr = ptr + n
end
socket:close()
end, "data-sender")
end)
app.sleep_until(function () return complete end, nil, 5)
server:close()
end