I need to make a web application in which there are two sites, A and B. A is like a control board with a lot of options, which will be open on a mobile device via a local server over wifi. Triggering the buttons on A should change the content on the Site B which is open on a computer in realtime. Much like a presentation but the two sites need to be different. What would be the best way to achieve this? I am a self taught programmer, with a basic knowledge of web technologies (HTML, CSS, JS, PHP, MySql) , processing and Java.
An idea might be like running ajax requests in certain interval on site B, that checks if there's any update from site A. And any action on site A is stored in a database or file. Then upon the triggered ajax request the script on site B makes a cURL request to get the stored update from site A and changes the content on site B accordingly.
Related
From my understanding the Java Client is what is rendered onto the browser such as the javascript, "the client side" for example what the user see's (tables, html, the sorting etc) things in the jsp. The server side is the servlet that makes the connection and call the specific class's based upon the request. I feel as though I am completely wrong as when I do research I am getting different answers. CAn I get some clarification on this please.
Java running on the client side means the end user needs Java installed and is running a Java program on their computer. This could be a standalone Java executable program (a traditional application), or it could be through a browser running a Java applet. Either way the end user's computer is actually running the Java code locally.
Java on the server side means that all the Java processing happens on a server somewhere, and the person accessing the site or service doesn't need Java installed. Servlets and JSPs fall into this category. The server does all the processing and then returns HTML/Javascript/CSS, etc to the end user. The user's web browser receives and processes those files to display the web site.
It sounds like you are getting confused because web browsers use Javascript to display dynamic sites, but Javascript is a totally separate language that has nothing to do with Java. In other words, a web site could be powered by Java servlets on the back end and could also use Javascript on the front-end, but they aren't directly related or dependent on each other. All the HTML, Javascript, CSS, etc that make up the web site are processed by the user's browser and the user doesn't have to know or care how all that stuff is generated on the back end.
for my master thesis I need to keep track of google searches that the users perform. It should be a web project. At first I want to setup a server (that acts like a proxy) to monitor all actions (search queries) performed by the user.
The server should deliver the google search page. I need to keep track of the input the users make and the corresponding results returned from google as well.
My questen is now.. How should I start?
I am not really sure which webserver to use. Should I use tomcat / jetty / or something else?
What about Java Server Faces or Servlets? I worked with JSF long time ago but I am not sure whether its a good decision to use it.
The server should deliver the google search page. Here is my idea: The user connects to my server. The server "reads" the google page and returns it (the source code) to the user. I think of using a listener on the default search field to monitor the search queries of the users. But how is it possible to monitor the results returned from google? The google site itself uses JavaScript I guess. So when the user makes some input it is directly sent to google and the results are directly shown on the webpage thus my webserver does not see anything from the connection between the client and the google services.
The main idea is to monitor a search query and the corresponding search results.
I just need some help and ideas to get started. This is just a small part of my thesis. I do not want to start from zero during my editing time thus I want to make sure that I make the right choices before I start.
Thank you in advance... best regards.
You could use netty as a proxy and just filter and log all search queries. But then again why even use java? From what you describe you wan't to play man-in-the-middle and manipulate/log http traffic.
A quick google search came up with this for python: https://code.google.com/p/proxpy/
Edit: and similar in java https://github.com/adamfisk/LittleProxy
I currently have a multiplayer card game developed and working in Java and it is working in the console. The game is similar in format to Bridge and Spades, minus the bidding process. It is a four-player game, and players take turns playing a card.
I am currently working to convert this to a browser-based webapp, and am adding Spring MVC, and using HTML, JavaScript, and AJAX for the UI and communication with the backend. I have a good idea of the approach I want to take on getting this to work single-player against the AI, allowing the user to play their card and using an AJAX call to get the next three plays from the server.
However, I'm wondering what kind of approach I would need to take for this to be multiplayer. I have seen some references to "Socket-programming," which I am unfamiliar with, but those seem to revolve around Java applets, instead of a browser-based app.
Basically, I am looking for a way to ensure that when a user starts a game and someone else joins, how do I ensure that they are connected to the same game, and are able to see each others' plays? I am asking this now before I have the UI fully developed for single-player, because I want to avoid a complete redesign to support multiplayer functionality.
Since you are creating a multiplayer game, you will need to have at least one server for your client(s) to connect to. Since you want to make this browser based, you will most likely need your own server (rather than having one of the clients be a server). When a user joins a game, it is logged on the server where that user is. When a player performs an action, the server processes the action, then sends a notification to each of the other clients connected to that room. At that point the clients UI updates.
In the past, you could not do this with pure HTML / JavaScript as you cannot open a socket. Which means, the server could not notify the clients. However in HTML5 you should be able to use WebSockets to achieve what you are doing with a server in the middle. The WebSocket API
However, if you don't want to use HTML5 WebSockets, there is another technique that imitates Sockets in JavaScript. That is, the server can talk to the clients. This technique is called long polling. The client sends a request to the server asking for an update, if there is no update available, the server holds the request until an update is available and sends it back to the client at which point they make another update request. Simple Long Polling Example
Another option, if you are very familiar with Java you may wish to check out Google Web Toolkit. GWT is a subset of Java that is compiled into HTML and JavaScript for the front end and if needed creates a Server Side java executable that you can use with TomCat or another web service. In this option, you have a few libraries that allow you to write socket-style code that will be compiled into Long Polling JavaScript.
Best of luck!
I need to load somehow the html code of a webpage A into a javascript string of another webpage B, on a different host. I know this is impossible to do with javascript alone because of the same origin policy, and I know I could do it loading the page via php on my server and then send results back to the user's client but I wouldn't be able to handle so many requests, so I need it to be done directly by the user's browser. I can use nearly whatever browser scripting language/applet framework common enough to be installed on the majority of my users' computers, like flash and java.
On example, what if I use flash or java to load the external html code and then call a javascript callback function providing the source? Could this work?
Do you have ANY idea? I gratefully accept any suggestion, and I REALLY appreciate examples!
Thank you very much!
Matteo
It would require a digitally signed and trusted applet in order to reach cross-domain, short of the user running a plug-in 2 architecture JRE and the site implementing a Cross-Domain XML.
Ordinarily, unsigned Java applets or applications may only connect
back to the web server from which they originated. This restriction
prevents an applet from causing denial-of-service attacks by making
rapid connections to arbitrary machines on the Internet.
In Java SE 6 update 10, both the Java Web Start and Java Plug-In
technologies contain preliminary support for cross-domain policy
files, which specify how unsigned code may access web services on the
Internet. The crossdomain.xml policy file is hosted on a given server
and allows either selected clients, or clients from anywhere, to
connect to that server. Cross-domain policy files make accessing web
services much easier, particularly from unsigned applets.
"via php on my server and then send results back to the user's client but I wouldn't be able to handle so many requests"
So many requests? That is not so many reqs; just making php script to read couple page and creating new page depending the data. If that is too much for your server ..hard to believe.. you sure can do that kind of thing with flash (clients computer) to load those two pages, and parse the datas to one html page and display it (via js) to clients browser. Kind of weird question after all.. perhaps i did not understand it :)
I have a java application that will take the image as an input and output another image. I have a website with a popular host (PHP+MYSQL Hosting). I want to create a page on the website with PHP with a form where a user can upload an image which will then pass the image onto the Java application.
What I am planning on doing is when then user uploads the image, it gets stored in a folder on the web server. I will then call the java app on the server passing the url of the image as an argument and then the java app will output another image, let’s say, to a result folder. The PHP page after the execution will then display the result image on the browser.
Now my questions are:
Is it possible to execute java apps on popular webhosts (for example mine is WebHostingBuzz.com)?
The java app is fairly heavy as it does a lot of image processing. Should I offload the java app to another web server? If yes, are there any services that will run my java app?
(Optional) It’s a demo of my java app and I don’t want to store the images people upload. Is there a way where I can directly pass the uploaded image to the java app and output the image generated directly instead of storing it on the web server? I would prefer this because, if the image is big, I can make PHP stop the execution after a timeout.
How do I communicate with the java app from PHP for info on its execution, for example When PHP calls the java app, the page has to wait till the app finishes processing? I want the java app to send a response to the PHP page saying that the processing is completed and the page is redirected or refreshed accordingly.
I hope you get the idea, please suggest the technologies that I can use to implement this and also if you have a better idea, post it!
Thanks!
Now my questions are: Is it possible to execute java apps on popular webhosts (for example mine is WebHostingBuzz.com)?
It's technically possible. But the hosting has to install JRE at the host and give the PHP user sufficient OS-level and filesystem-level permissions. So you're really dependent on the hosting whether they provide this opportunity. Best is to just contact their support team and ask it.
If it is supported, you could just use shell_exec().
$result = shell_exec("java -jar /path/to/imageprocessor.jar " + $imagepath);
if ($result) {
// Shell execution succeed.
} else {
// Shell execution failed.
}
For asynchronous communication / background processing, the client has to fire an ajaxical request.
If it is not supported, consider porting Java to PHP. The GD image library has pretty a lot of functions which may be of use.
Google App Engine allows to host Java (and Python) web applications. The SDK and the basic account is free of charges. With the SDK, you could develop and test the application locally and then simply deploy to App Engine (NetBeans and Eclipse plugins are available).
Then the PHP app could send the data in a HTTP POST to the Google App Engine application and get the result in the response data.
Or the data is stored first in a database blob and a processing job is put in a task queue (a 'message queue'). This has the advantage that the PHP client request will return immediately after the data has been POSTed. Then, the PHP application could poll for the result data while Google App Engine processes the image. The PHP side would be more responsive this way.
Wouldn't it be easier to make your java app a web app, that PHP could call via an url in wich he would put the url of the image so java can download it?
like http://yourjavaserver/imageprocessing?imgurl=IMAGE_URL
and the java servlet would reply with the image file itlsef.
You can look for "java hosting" on google, to find a host for this, but it's more expensive than PHP hosting. Maybe the best choice would be to get a dedicated server which could host both PHP and java applications...
I think your best bet here is with your java app running as cron(or a deamon) that can load the file details from the database. This will require a (one or more) page-refresh on the users part after the generation is complete, at which point your script can recall the image from the database/filesystem.
I do not think you will be able to do this in real-time due to timeout restrictions on the PHP webpage. However, you could write a java applet that can take the file and process it before sending it to the server (or depending on how you intend to use it, perhaps you do not need to upload it after the transformation?).