socket receive loop never returns -
i have loop reads socket in lua:
socket = nmap.new_socket() socket:connect(host, port) socket:set_timeout(15000) socket:send(command) repeat response,data = socket:receive_buf("\n", true) output = output..data until data == nil
basically, last line of data not contain "\n" character, never read socket. loop hangs , never completes. need return whenever "\n" delimeter not recognised. know way this?
cheers
updated include socket code
update2
ok have got around initial problem of waiting "\n" character using "receive_bytes" method.
new code:
--socket set above repeat data = nil response,data = socket:receive_bytes(5000) output = output..data until data == nil return output
this works , large complete block of data back. need reduce buffer size 5000 bytes, used in recursive function , memory usage high. i'm still having problems "until" condition however, , if reduce buffer size size require method loop, hangs after 1 iteration.
update3 have gotten around problem using string.match , receive_bytes. take in @ least 80 bytes @ time. string.match checks see if data variable conatins pattern. if exits. not cleanest solution, works need do. here code:
repeat response,data = socket:receive_bytes(80) output = output..data until string.match(data, "pattern") return output
i believe way deal situation in socket set timeout.
the following link has little bit of info, it's on http socket: lua http socket timeout
there 1 (9.4 - non-preemptive multithreading): http://www.lua.org/pil/9.4.html
and question: http://lua-list.2524044.n2.nabble.com/luasocket-howto-read-write-non-blocking-tpc-socket-td5792021.html
a discussion on socket can found on link:
http://nitoprograms.blogspot.com/2009/04/tcpip-net-sockets-faq.htmlit's .net concepts general.
Comments
Post a Comment