24 lines
563 B
Lua
24 lines
563 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 fr,po,msg = ""
|
|
repeat
|
|
_,fr,po,msg = event.pull("net_msg")
|
|
until fr == addr and po == port
|
|
local ml,s = tonumber(msg), ""
|
|
for i = 1, ml do
|
|
_,fr,po,msg = event.pull("net_msg")
|
|
if fr == addr and po == port then
|
|
s=s..tostring(msg)
|
|
end
|
|
end
|
|
return s
|
|
end
|