Good day!
I am planning to create a multiplayer board game using java, jquery, dwr, ajax. In my java, i will store data into application level. Using dwr and ajax, I can retrieve data without the need to refresh my browser and do JQuery animation accordingly. My problem is, If there are many players, how can the JQuery animation automatically changes for everyone to see it without the need for them to refresh their browser.
For example, player 1 is on grid(1,1). My code will allow player 1 to go to grid(1,2), grid(1,3) etc. using Jquery with corresponding animation. But the other player(using another browser) will not be able to see this. How can i make the other player see it? Is it possible that the second player is also accessing the browser of player 1 remotely? Any suggestions/books/articles/code samples regarding this would do.
Thank you.
1) You can do it with Ajax by calling ajax calls every second for every user to check if there are changes on board.
2)To not to make many ajax calls you can use Comet.
3)From performance view the best way is to make TCP server and use sockets. You can use Websockets or Flash socket proxy.
Related
Play's flash is a "temporary storage mechanism that is kept for the duration of the next request", using cookies.
Is it possible to read the flash from javascript?
I want to implement a generic client-side notification mechanism, and also access that mechanism from the server. What I imagine is for any controller to do:
flash.put("notification", "You have been notified");
And then for my main.js to check if the "notification" flash exists, and if it does display it above (similar to Stack Overflow's notification mechanism).
However, I suspect that flash might be encrypted in a way that the client side cannot read it. I haven't found any code samples that show how to read it from the client side JS (not in a template). Is this possible directly?
As I'm writing this question, I'm actually coming up with a way to implement this: I can put a hidden div in the main template that all my views extend, and access that div from JS. Does it make sense? Is there a simpler approach?
I don't think it's possible to use JavaScript to read flash, even via the cookie. That cookie is actually encrypted with a security seeds (application.secret) configured in your application.conf.
However it is possible to implement what you want.
Create a tag to export flash variables into Javascript object.
Call that tag in your view.
Your main.js use that exposed variable to do whatever it want.
For me you have two solutions
In your view call a javascript function with the value as an argument, then in javascript you can store it in an object for later use
The flash cookie isn't encrypted, it is sign, so you can read it but you can't modify. Use a tool like firebug to see the content of your flash cookie
I have been developing an AJAX web application using GWT. I've read several blogs and forums about this question and left with no clear idea. I understand that GWT is an AJAX application, that supports only stand-alone web application. By stand-alone, I meant GWT to be a single web page that would suffice the user requirements. However the use case I have is pretty complex and I'm stuck in this use case that doesn't let me proceed.
My usecase(s) goes like this:
Usecase #1: There is an order entry form where user will enter a search string to search for a particular item. With GWT, I could display the result in a table (say celltable). However, when I click a column in the cellTable, I want the value of the column to be sent to the server and display another page that will display only the details of the selected column. I'm not sure how to accomplish this.
Usecase #2: Let's say the web application I develop is called "InventoryControl" and I have different requirements such as:
display Available stock
display Order stock
display Manufactured unit
and Using Java servlets, I could just type http://localhost/availableStock?stockId=1234 on my browser to get the "Display available stock" for the given stockId and then http://localhost:orderStock?stockId=1234 to get the "display order stock" and similarly "display manufactured unit". Is the same possible using GWT? i.e. when I type http://localhost/availableStock?stockId=1234, is it possible to read the parameter being passed and then display the corresponding page?
If these are not meant to be guaranteed by GWT, should I stick with Plain old JAVA servlets/JSP?
Thanks in advance.
Ashok - Please note, what filip suggests above does not require multiple "pages" in the sense of additional html host pages. You can build a panel holding your display of the details, and swap it into the rootpanel of your host in the onSuccess() of your rpc call. The GWT history mechanism allows you to assign anchors to these "places" and provide a mechanism to map these anchors to specific display classes in your code.
GWT already has a mechanism for handling multiple page applications. Have a look at Activities and Places. You can define each page as a place in your application, and use the GWT mechanism to go from place to place at any time. Using places also allows you to easily add tokens/query parameters to each "page", in an OO manner, without having to worry about populating/querying the URL directly. Have a good read of the link!
I'm implementing a simple checkers game (java applets as clients + servlet) where two players can connect to the servlet and play. As I'm just beginning with applet-servlet programming, I have some problems with the proper communication.
Let's suppose the game begins and first player moves. Then I have to send his move to the servlet which should inform the other player. And here I don't know how to do that. How the servlet can pass received data to another applet, not the one that sent it? How and where should the servlet keep the info related to players so that it can recognize which one sent the data?
Fisrt: the servlet won't pass data or message to any servlet from its initiative.
It will have to wait for the applet to send a request, and then will be able to send a proper response.
So, the simplest seems that your applets regularly send requests to the servlet, like "what's up?". It's the polling system ome is talking about.
To recognize which player is polling, give them an id when they first access your servlet (register ?), and make that id present in every future request.
Is that clear enough ? :)
(and yes, next step is to use COMET)
I want simple java code that enables submission of same/similar data to multiple websites at a time...All the values are initially asked from the user, and just before submission, only multiple choice values (like radio buttons) and captchas are shown on screen. After the user has filled in these values all forms are submitted.
Is it possible to do this in
(a) Regular java application
(b) Google App ENgine Java application
Also some sites require new user to register and then login, only after that multiple form submission has to be done. Can this be implemented in java and how?
Regards,
Arvind.
You can use Ajax to submit multiple forms.
In the URL below, the author uses Jquery and AJAX with PHP to do it.
Use the same concept using JSP and you should be good.
http://www.9lessons.info/2009/06/submit-multiple-forms-jquery-ajax.html
I have a Java web application which stores some data in the session. The data in the session changes as the user interacts with the application (e.g. flow is managed by a controller, each controller has several form pages, on each form page some data is updated in the session and flow goes to the next form page).
The problem is that some users are opening more than one tab to the application, each tab with a different step in the flow. At this point data in the session is messed up since the tabs share the same session (app uses cookie managed sessions).
Telling the users to use different browsers to avoid sharing the same session id (e.g. one Firefox window and one IE window) is not an option since surely at some point somebody will forget to do this and instead use tabs, thus messing up their data.
Adding some verifications that detect that another flow is requested from another tab and display a message to the user saying this is not allowed is not an option either since it pisses of the users and we don't want that do we? :D
The fact is that using another tab is useful for the users because they are more efficient in what they use the application for, so I am keeping this option. But the question now is how best to manage the one session data for the more tabs?
What I thought of, was to have the controller generate a token when it starts the flow and pass this token to each form page which in turn sends it back to identify itself. If another tab requests the same controller action when there is an ongoing flow then generate another token and pass that around.
Basically, I want each flow to have a token and inside the session I won't just keep one set of data but have a set of data for each token and then match requests based on the token.
Now the problem is that this approach will need a lot of rewritings to the application and I was wondering if there is a best practice for managing such a situation or can someone suggest other approaches. I am open to ideas.
Have you encountered this situation? How did you handle it?
This is usually done by assigning a windowId for each tab/window and passing it on each request. Jsf supports this via orchestra. Spring mvc will support it in the next version.
I recently needed this for a simple case, so I implemented it myself. Took half an hour. However, my scope was very limited:
pass a windowId with each request, and return it back for the next request. The first time - generate it.
for any attribute you want to store in the session, put a Map<String, Object> where the key is the windowId
This is exactly what Seam was created to handle. In Seam there's a concept called a Conversation which basically does exactly what you are explaining. Conversations are basically are a way to divide the Session into many pieces that can expire at some timeout. You can look at the source code for org.jboss.seam.core.Manager class to see how it's actually implemented and get inspired ;)
Depending on the complexity of your application, you may want to investigate implementing tabs within your application. This gives you wholesale control over the flow, while still providing users with the functionality they want. I'd argue it's, bugwise, the most robust solution, since you won't have a dependency on the way the browser handles sessions, minimising the number of "known unknowns".
Of course, there'll be potentially a large upfront cost to this, depending on how your application is structured. Without more information about your app, you're the best placed person to decide.
You can also try to wrap your application inside Adobe Air
And then limit your web application to be only accessable from this air. By doing this you dont need to consider the web browser fragmentation and their unique behaviour.