i'm trying to push data from server directly to the client's php web page. i have googled this question many times and i don't want to use ajax push engines or other stuff such as cometD (if you know what i'm talking about). i would like to know if there is any way to put a program up on my server that would send data to all connected client. i would prefer this to be done in c or c++ or c#, i can program it myself i just want to if it is possible and how.
2 Answers
Maybe you're not getting how HTTP protocol is working. You should document yourself more about it first. I'll try to explain how to use it for your case:
Polling: Each X seconds, the client will request a webpage with the content you want. This is the standard way of using HTTP: Client send a GET, Server send the response.
Push: Each client will request a webpage, but the server will actually wait you for sending the message. You can use this http channel to "push" data: Client send a GET, Server wait until he have a response to send
As you see, i'm not talking about any language implementation, just about how the HTTP protocol can be deviated to do what you want. The bad side of Push approach is that you will have X sockets open for X clients, even when the client is idle. It's not happening with the Pull approach, the socket is closed when the response is sent.
Now, if you want to do it, you need to start the connection from the Client. This is where the "Ajax" part can be useful, let's see in jquery:
$.get('/wait_for_message', function(data) {
alert('My server send:' + data);
})
Your server will got a GET /wait_for_message HTTP/1.1 request. Instead of sending back the data, you can save this socket in a list of "client that waits something". Then when wanted, you can iterate through this list, write data to all the socket, and tada: all the clients will receive the data.
Now this mecanism is not easy to get it right, this is why you could use another project for it, as others peoples have proposed.
Comments
You can write/modify a very simple web server in any language to format and serve data from a database even ignoring what the actual request is. All you need to do is to write a header and data to a socket. You can do the same thing by actively initiating the connections according to some list.