How can I push from webserver to web client? lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- egsuh · 2023-07-20 08:09 Are there any way to do this from fpweb (cgi module)? ---------------------------------------------------------------------- Warfley · 2023-07-20 09:06 Server Push is a feature of HTTP/2. FpWeb only supports HTTP/1.1 There is a workaround in that you can use long timeout requests. I have once worked with a protocol that did that to basically turn the request response system around such that the server can basically send requests to the client, it looked like this: Code: Text [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i [C] [S] | | +----HTTPReq(Init)---->+ | [...] | |<-HTTPResp(Req(id0))--| |--HTTPReq(Resp(id0))->| | [...] | |<-HTTPResp(Req(id1))--| |--HTTPReq(Resp(id1))->| | [...] | |<--HTTPResp(Close))---| Basically with an infinite timeout each request will just sit there and the server can answer any time it has a new request. The answer from the client then opens a new long living request that will wait for the next server message ---------------------------------------------------------------------- egsuh · 2023-07-21 04:10 It's brilliant. Warlfey, I know that you have written web-socket server and client. Is it possible to use them together with web server, both server and client side? ---------------------------------------------------------------------- Warfley · 2023-07-21 08:27 For a Webserver or FastCGI application you could just on startup create a new thread that creates a Websocket server listening on another port. For CGI applications this is not that easy, because the CGI App will be started for each request individually, meaning you don't have any memory surviving between the requests. What you could do instead is create a seperate process running the websockets server on a different port, and as you are using CGI, you will be behind another webserver like nginx or apache, so you can simply put that websocket server and port behind this as a reverse proxy, so you don't even have to deal with different port numbers. Then when you get a request, you can encode websocket connect infomration within that request, within these informations (e.g. as part of the path), you can encode the session information for that client. When the client connects via websockets you then look up this session (e.g. in an SQL database) and know to what original request it belongs. For further requests you can then synchronize via the session database. ---------------------------------------------------------------------- egsuh · 2023-07-21 09:24 Thank you very much for your kind explanation. Actually I think I may resolve even with CGI because pushing from server is only when there are a request from other client. Let's assume that there are clients 1,2,3, ... which I'll call C1, C2, C3, etc. And there is a server, S. When C1 send a request to S, then S will send some content to either one of C2, C3,.... ---------------------------------------------------------------------- toby · 2023-07-26 18:41 Ho egsuh your c1/c2/c3 thing might have a few problems you want to send an unsolicited page to their computer after loading a browser and after turning on their computer? sounds like something a 3 letter agency would love to have i sure hope http2 can't even do it here is a cgi get thing with a refresh that i found fun to do - maybe someone can comment about if it can be done with post variables also? Code: Pascal [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program push; uses sysutils; // for getenvironmentvariable//uses sysutils, dos; // for getenv const days : array[1..7] of string = ('Sunday ', 'Monday ', 'Tuesday ', 'Wednesday ', 'Thursday ', 'Friday ', 'Saturday '); var s, z : ansistring; hour, minute, second, sec100 : word; year, month, day : word; begin writeln('Content-type: text/html; charset=utf-8');writeln; s := getenvironmentvariable('QUERY_STRING'); // uses sysutils 'QUERY_STRING' for get variables// s := getenv('QUERY_STRING'); // uses dos; write('');write('
');write('