2017-08-02 23:52:52 +10:00
|
|
|
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 = {},"","",""
|
2017-08-02 23:52:52 +10:00
|
|
|
repeat
|
2017-08-03 12:24:54 +10:00
|
|
|
t,fr,po,msg = event.pull("net_msg",10)
|
|
|
|
if not t then
|
|
|
|
return
|
|
|
|
end
|
2017-08-02 23:52:52 +10:00
|
|
|
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
|
2017-08-02 23:52:52 +10:00
|
|
|
if fr == addr and po == port then
|
|
|
|
s=s..tostring(msg)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return s
|
|
|
|
end
|