add localhost 'network' library test

This commit is contained in:
MihailRis 2024-11-27 17:53:23 +03:00
parent af5902f98e
commit 495dd5f8f2

View File

@ -1,3 +1,25 @@
-- use for engine development tests
-- must be empty in release
-- must not be modified by content-packs
local server = network.tcp_open(65343, function (socket)
print("connected client", socket.id)
socket:send(utf8.tobytes("Hello, World!"))
socket:close()
end)
print("server", server.id)
local socket = network.tcp_connect('localhost', 65343, function (socket)
print("connected", socket.id)
end)
function on_world_tick()
local result = socket:recv(128)
if result and #result > 0 then
print("received from server:", utf8.tostring(result))
end
end
function on_world_quit()
server:close()
end