OC-PsychOS/modules/net/net-ext.lua

28 lines
641 B
Lua

net.mtu = 256
function net.sendstring(addr,port,msg) -- for sending lots of data
net.send(addr,port,math.ceil(msg:len()/net.mtu))
for i = 1, #msg, net.mtu do
net.send(addr,port,msg:sub(i,(i+net.mtu)-1))
coroutine.yield()
coroutine.yield()
end
end
function net.recvstring(addr,port)
local t,fr,po,msg = {},"","",""
repeat
t,fr,po,msg = event.pull("net_msg",10)
if not t then
return
end
until fr == addr and po == port
local ml,s = tonumber(msg), ""
for i = 1, ml do
t,fr,po,msg = event.pull("net_msg",10)
if t == nil then break end
if fr == addr and po == port then
s=s..tostring(msg)
end
end
return s
end