0

I can't manage to read the data from a luasocket. If i read more than the available data, the function call keeps blocked waiting until the client decides to close.

https://github.com/StringManolo/LuaServer/blob/main/tmpServer.lua#L216

line, errorStr = clientObj:receive("*a")

I'm using this command to test:

$ curl -X POST -d "a=b" http://localhost:1337 -v

Got same problem using Chrome to send a request to the Lua server.

I tryied to read byte to byte, line to line, all, etc.

String Manolo
  • 35
  • 2
  • 8
  • 1
    http://w3.impa.br/~diego/software/luasocket/tcp.html#settimeout – Joseph Sible-Reinstate Monica Nov 15 '20 at 00:52
  • 1
    Although if you're trying to build a Web server, why not just stop reading after you get a blank line instead (and if there's POST data, use the Content-Length)? – Joseph Sible-Reinstate Monica Nov 15 '20 at 00:52
  • I tryied the settimeout but the receive function is blocking when i read more bytes than expected so the settimeout is not working at all as i tested before asking here. Reading what the content-length says is not a real solution. Anyone can just open in loop a netcat and DOS the server sending a bunch of content-length: 100\r\nbody:a=b requests without closing the connection. – String Manolo Nov 15 '20 at 01:51
  • Get filesize and send that information first, https://stackoverflow.com/questions/10712622/how-to-get-the-file-size-and-delete-file-in-lua Then open socket and accept that amount of data. `clientObj:receive( expected_number_of_bytes )` – Doyousketch2 Nov 15 '20 at 14:46
  • There is no expected number of bytes. Is a web server to use with your browser. – String Manolo Nov 15 '20 at 19:51

0 Answers0