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

28 lines
641 B
Lua
Raw Permalink Normal View History

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)
2017-08-03 12:24:54 +10:00
local t,fr,po,msg = {},"","",""
repeat
2017-08-03 12:24:54 +10:00
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
2017-08-03 12:24:54 +10:00
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