javascript - Need to send information between Java application and webpage -
i have multi-player game works on sockets, interested in adding spectator view (and chat) via web page , javascript.
i need send few bytes of information every few seconds webpage, , of course chat messages , game server (they have logged in send messages).
can use websockets? compatible regular sockets? other methods use? (i'd prefer not use database polling)
you can use httpserver inside java application share information. it's pretty simple - few lines of code. of course computer should available other computers web browser.
that's 1 way communication client server. if need 2-way communication still need obey http rules (not because of java because use browser client).
here do. in javascript open connection, - ajax, image, javascript source new javascript dynamic object (that's do). on server side open don't close connection - wait till have send. when have - send it. browser have @ exact moment. plain , simple. however, there necessary trick: if server waits long (2 minutes) browser closes connection. in case javascript should ready , make same request again. , os repeats. on server side connection closed new 1 opened , wait when ready. 1 more trick - when new request browser side - don;t forget cache. not have same answer cache add unique request. example current time parameter.
Comments
Post a Comment