Thanks for the reply. I am completely new to server technology. I will keep digging as it may be an Apache issue.
I have implemented server sent events in my own hand rolled LiveCode server (which admittedly will not be 100% compliant) and this works for me. The web browser shows the connection staying open, I can transmit Server Sent Events at my discretion and they are correctly recognised as Events by the browser in the debugger.
Code is simplified below...
Code: Select all
global gClients
accept connections on port 80 with message ... //blah blah .... which triggers "newRequest" when web page is requested
on newRequest pClient, pRequest
//.... process headers here, lots of httpd stuff, but the Server Sent Event Section is as follows...
if line 1 of pRequest contains "/sse.lc" then -- check if the request is for Server Sent Events
// keep track of the clients
if pClient is not among the items of gClients then
put pClient & comma after gClients
end if
sseResponse pClient
return empty -- do not continue with complete web request
end if
//... lots of other httpd type stuff
end newRequest
on sseResponse pClient, pData, pEvent
if pData is empty then put the seconds into pData -- should never be empty
local tResponseHeader, tResponseBody
put statusLine(200) into tResponseHeader -- function simply returns "HTTP/1.1 200 OK" & crlf or some such
put "Cache-Control: no-cache" & crlf & \
"Content-Type: text/event-stream" & crlf & \
"Connection: keep-alive" & crlf after tResponseHeader
put "id:" && the seconds & "/n" & crlf into tResponseBody
if pEvent is not empty then
put "event:" && pEvent & "/n" & crlf after tResponseBody
end if
put "data:" && pData & "/n/n" & crlf after tResponseBody
write tResponseHeader & crlf & tResponseBody & crlf to socket pClient
end sseResponse
This is the only way I have been able to deal with things like multipart-requests and Server Sent Events up until now. I have complete control of the TCP connection. I was hoping to migrate some of the features I had implemented to the "cloud".
As an aside. I did skim across the spec for HTTP/1.1 and I too interpret this as "connections are kept open unless "Connection: close" is specified. Only then will I terminate the connection and tidy up my client lists.
Long Story Short... I wish we could control the TCP connection for web requests using lc. I don't see why the connection is automatically closed after writing/putting data. (Especially if I have specified "Keep Alive" in the header.