20.11.2017, 10:35
I have an "old" piece of code that generates a html response for clients that connects to my lm:
http://192.168.x.x:19001/getdata/test
Results:
Chrome : ERR_INVALID_HTTP_RESPONSE
IOS Safari : cancelling load from .... because it is using HTTP/0.9
Internet explorer and Edge works great.
Anyone a solution?
http://192.168.x.x:19001/getdata/test
Results:
Chrome : ERR_INVALID_HTTP_RESPONSE
IOS Safari : cancelling load from .... because it is using HTTP/0.9
Internet explorer and Edge works great.
Anyone a solution?
Code:
-- init server handler
if not ready then
require('copas')
-- list of client sockets
clients = {}
-- incoming data handler
function datahandler(sock, data)
local ip, port
ip, port = sock:getpeername()
-- send reply
if string.find(data,"GET /getdata/test") then
sock:send(htmlbody)
--else
--log(string.format('[server] data from %s:%d - %s', ip, port, data))
end
end
-- connection handler
function connhandler(sock)
-- enable keep-alive to check for disconnect events
--sock:setoption('keepalive', false)
local ip, port, data, err, id
-- get ip and port from socket
ip, port = sock:getpeername()
-- client id
id = string.format('%s:%d', ip, port)
--log(string.format('[server] connection from %s', id))
-- save socket reference
clients[ id ] = sock
-- main reader loop
while true do
-- wait for single line of data (until \n, \r is ignored)
data, err = copas.receive(sock, '*l')
-- error while receiving
if err then
--log(string.format('[server] closed connection from %s:%d', ip, port))
-- remove socket reference
clients[ id ] = nil
return
end
-- handle data frame
datahandler(sock, data)
if data == "" then
--log("stop")
break
end
end
end
-- bind to port 10001
tcpserver = socket.bind('*', 19001)
-- error while binding, try again later
if not tcpserver then
os.sleep(5)
log('[server] error: cannot bind')
end
-- set server connection handler
copas.addserver(tcpserver, connhandler)
-- create udp server on port 10002
udpserver = socket.udp()
udpserver:setsockname('*', 19002)
udpserver:settimeout(0.1)
ready = true
end
-- perform server tasks for one second (5 x (0.1 + 0.1))
for i = 1, 5 do
message = udpserver:receive()
-- got message from udp, send to all active clients
if message then
--log("message: " .. message .. " : " .. chartobyte(message))
for id, sock in pairs(clients) do
--log("client id: " .. id)
sock:send(message .. '\r')
end
end
copas.step(0.1)
end
-- all dynamic pages
htmlbody =
"<HTML>\n"..
"\n"..
"<HEAD>\n"..
"<title>Web Communication</title>\n"..
"</HEAD>\n"..
"\n"..
"<BODY>\n"..
"Web Communication \n"..
"<h3>Test</h3>\n"..
"<pre style='white-space:normal;'>"..
"</pre>"..
"<br>"..
"</BODY>\n"..
"\n"..
"</HTML>"