Reputation: 6441
I was thinking syncronization events between client and server. General idea about it is that client should to request to server periodicaly for checking changed datas. The problem about it is that unneccessary requests happenning from client side even there is no any changed stuff on server side. So i thought it may be possible to request clien't browser when an event happened but i am not sure it is possible or not. Recent days i have heard that this will be possible with html 5.
Is it possible to request clien't browser from server in web ? If it is possible so is it bad practice ? What can be common scenearious for request client ?
Upvotes: 0
Views: 450
Reputation: 6588
The server doesn't "request" the client, rather the client initialises the conversation by opening an HTML 5 WebSocket. That socket then stays open, and the server can push data back to the client at any time.
You can do this in HTML 4 using "long polling", where a client makes a request and the response is also kept open for a longer period. The problem here is that the client cannot send another request on the same socket, so needs to hold two sockets open to the server - one to send request, the other to received responses. This is only bad if you have many many clients attached to the server and are already on the limit of how many connections your server can handle.
In any case, you want to configure the server to use "non-blocking" (NIO) connections, so that it doesn't need one thread per client, because handling anything more than a few thousand concurrent threads seems to bring the server to a stop. Using a non-blocking solution, you can theoretically have 50 thousand or more connections per server instance, although how useful that will be is questionable, because of the amount of requests it can process quickly with that many connections. If every client makes a request per second, you will be handling 50 requests per millisecond, which is unlikely to give you enough time to do anything resonable with say a database.
See the following links:
http://blog.maxant.co.uk/pebble/2011/06/21/1308690720000.html
http://blog.maxant.co.uk/pebble/2011/05/22/1306092969466.html
http://blog.maxant.co.uk/pebble/2011/03/05/1299360960000.html
Upvotes: 0
Reputation: 1039278
HTML5 allows for the server to PUSH notifications to the client thanks to the WebSocket API. You will need a WebSocket server. There are many implementations out there. The only problem with this specification is still a draft and subject to change. For example the spec recently changed in Google Chrome browser. So it is not yet widely supported if you will.
Upvotes: 1
Reputation: 2831
It is possible with web sockets or a tool that abstracts them. See this post for a similar question/scenario:
Upvotes: 1