javascript - Changing pictures on servlet with websocket -
i have small website each times user cliks on image, changes. made on html5, js, java , wildfly. know how update image others users browsers well? mean, each time clicks on image, changes, , want change on other users on website moment well. made connection of javascript , java json, how can send message java javascript? json again?
thanks in advance
i can think of 2 options:
client side, poll server periodically, asking if should new image; if yes, it
connect websocket, , send notification server client telling new image
option 1 pretty easy implement. create endpoint on backend keeps track of "current" image. clients can hit endpoint, , update image if determine necessary. disadvantage polling server of clients.
option 2 bit more robust. websocket allows bidirectional communication. so, on server side still track current image. when client clicks image, send message (client->server) notifies backend change image. then, server can send out message open websockets notifying them need change image. message send clients contain image url or whatever information need display it.
hope helps.
Comments
Post a Comment