Making a chat app using AJAX, Servlet and JSP on GAE - ajax

I'm a CS student trying to do some side projects during this summer. One of my aims to is create a chat app which will be ultimately hosted on GAE. I am new to web development so I'm trying to shoot around in the dark hoping to hit the target but I guess it will be a major waste of my time. The rationale for using servlets and JSP is that GAE requires Java for the backend. I hope to use AJAX to do the front-end.
However it is hard for me to put all the technologies together to make it work. I am having trouble with the design. I don't need any codes, but rather help with the design patterns.
I am confused with how GAE works. Since GAE requires Java/PHP/Python etc, is it possible to deploy the client coded in AJAX using GAE? Do I require two GAEs, one for the client and one for the server which is coded in Java?
I am also quite lost with how to connect the AJAX technologies with the Servlet & JSP technologies. I'd appreciate it very much if you guys can provide a step by step instruction on the design pattern. Links to online tutorials will be very much appreciated. My style is to learn as I go.
Ultimately, my aim is to get an chat app (very simple one where all users can see each other messages) up and running on GAE to get a feel of the whole web development process (code, run, deploy).
Just a side note, I don't know any PHP/MySQL (but will learn later if I get the whole web dev thingy down to include database features).
Thank you all.

There's a LOT of stuff available out there to read if you just search for Google App Engine. Start with the documentation and work through the tutorials. It's not a waste of your time to learn, since you don't already understand it.
Google App Engine is essentially a distributed web server + database. AJAX on App Engine is no different from AJAX anywhere else - the server serves HTML+Javascript which runs on a web browser, and communicates back to the server.

Related

How to respond to ajax calls on the server side?

I have been working on a mobile app that sends an ajax call to the server and waits for a response from the server in json format.
I am wondering from the server side, how to respond to an ajax call? Could someone give me an example in code?
I check the server code of my project (written by other members of the team) and could not understand it. I can only see it is written in java and also some keywords such as apache, springframework, etc pop up. I am a total newbie for server side programming and I want to learn more about it. Could someone give me some tips on how to get started with those as well? How does a server work? Is it just like responding to various request? What language could you use to build it and what is Apache? I know this looks like a lot of questions so probably I need to get some basic knowledge first. Any help/tips/suggestions on readings is appreciated.
This is kind of a broad question, as there are a lot of different server-side technologies that can handle server side AJAX requests, but if you want to go the Java route, using Spring Framework makes it very easy.
Spring Framework is a large open-source Enterprise Java framework that has a variety of features which entire books rarely even cover.
(Apache is an open-source project that contains over a hundred different sub-projects, the most popular being a web server.)
Spring does have some specific tools to handle REST calls. Assuming your AJAX is making a REST call (which is what it sounds like), and your project is already using Spring framework, it is fairly straightforward (assuming you already know Java). The Spring framework handles all the hard stuff for you. There are a few different ways to do this using Spring, but check out this link for creating a simple REST service:
https://spring.io/guides/gs/rest-service/
Another route would be to look into PHP, which is a server-side scripting language. With PHP, you can handle AJAX requests without the need for an application server (most basic web servers speak PHP). There are plenty of good resources for this, but one of my favorites is http://www.tutorialspoint.com/php/
BTW - the TutorialsPoint site is great for Java and Spring as well

Dummies tutorial for Websocket in tomcat8 server and client

My first post.
I have experience of basic java servlet and jsp and have got my webpage implemented in tomcat7.
Regarding Websocket, I am finding difficult to build understanding of how to implement it, i want to use tomcat8 implementation of websocket api and uplift my webpage (jsp, java, jquery, tomcat7) to use the websocket features, have not been able to find the the tutorial that can guide me through, something like hello world example. any pointers (sample codes, tutorials)?
have tried to understand tomcat8 examples but not understanding them at all
You need to understand that you don't just "add" WebSocket to an existing web application.. to make it faster, better, cheaper, more scalable, etc. Instead, you have to completely re-architect the web-layer of the application to take advantage of its capabilities.
I suggest that you first read a lot about WebSocket and what the whole idea is before you try to write any code, using Tomcat or any other WebSocket-capable server.
Nick Williams has a forthcoming book that appears to cover everything in the web application world, and as I understand it, will have a great deal of information about WebSocket-based code. You will unfortunately have to wait until March 2013 (at least) to use that particular book.
I'm sure there are similar books available, or even online tutorials to help get you started using WebSocket. Just be aware that switching to WebSocket isn't some simple configuration option: it's a very disruptive change to any existing web application.

Pros & Cons Using static HTML5 + ajax + REST

For my new web project I am considering to abadon server-side processing of web pages in favor of just using static HTML5 pages. All dynamic content of the page will be loaded using ajax from a REST service. No need for php, jsp, jsf.
I came across this post and it seems I am not the only one.
What are the advantages and disadvantages using this approach?
I can imagine there are more client-server requests since many REST calls have to be made in order to gather all the information needed to display the web page.
I believe that we have much more PROS than CONS. One of the good ideias to give HTML pages trought a WEB app server, like apache, nginx, or ISS, is that you can apply more security and control to the container that is delivered.
BUT, HOWEVER
Use static content, like JS, CSS, and HTML5 to consume only services, is the next goal in software development. When you start to divide things like, API and UX, you can test then separatly, you can develop at same time, service and interface, and you have much more speed and quality to development.
When we look at a web page, and the weight that the DOM have, and how much cost for the app server to give all that container to the user, and sometimes less then 10% of this is JSON from a service, we need to start to rethink the architecture of our web app.
I have been developing apps like this since one year and a half now, all the projects, and be sure, we re not to come back to the past. Its very important to work oriented to services, and how to consume this services.
If you use for example, Amazon S3 to host your HTML,JS, CSS, IMAGES, files, you dont need a app server, only the REST api to consume and give the content to the user. Costless and very,very faster.

Phalcon php vs node.js

We are going to develop rest server for our application (and all logic is on client javascript).
So we thought to use Phalcon php, but we also need to create realtime chat system, which is much more easy to do using node.js. This made us think about using node.js instead of phalcon
Unfortunatly, we are not good expirienced in node.js, we love phalcon for its performance and internal beauty.
The quiestion is, did anybody compare phalcon and node.js performance? May be it's better to use node.js only for long polling chat requests, but i dont like when project is connected with so different tools.
You are trying to compare two different things IMO.
node.js has a lot of power and flexibility but so does Phalcon. If you want to create a chat application with Phalcon, then you will need to implement some sort of polling mechanism in your browser that would refresh the chat window every X seconds. Getting/Inserting the data from the database will be Phalcon's job. Javascript will be used to do the polling i.e. refresh the chat page every X seconds.
The problem with this approach is that you might be hitting your web server every X seconds from every client that has the chat application open - and thus refreshing the chat contents, even when there are no messages. This can become very intensive very quickly.
node.js has the ability to send messages to the subscribed clients instantly. Web sockets can do the same thing I believe.
Check this video out, which will give you an idea of how this can be achieved easily:
https://www.youtube.com/watch?v=lW1vsKMUaKg
The idea is to use technologies that will not burden your hardware, rather collaborate with it. Having a "subscription" notification system (such as sockets or node.js) reduces the load on your application since only the subscribed clients receive the new messages and no full refresh is needed from the chat clients.
Phalcon is great for the back end with its speed and it can be used to construct the message which in turn will be passed to the transport layer and sent to the client. Depending on how you want to implement this, there are plenty of options around and you can easily mix and match technologies :)
as #Nikolaos Dimopoulos said, you're trying to compare two different things.
But here is my advice, while you're experienced with PhalconPHP framework, and you want to benefit from Phalcon speed and performance, you can implement the web app in Phalcon FW, and the chatting system in Node.JS as a service.
If your web application "The Phalcon app" needs to push messages from the backend, you can use http://elephant.io/ library for that, I have done this before with Yii framework and Node, and it's working perfectly.
My advice is to use what you already know, experimenting with nodejs just for the chat application.
Mainly because you said you do not have experience with it, so, because the chat app is something a lot of people made you'll find plenty of examples.
By doing so you will learn a lot from node and might even think about migrating from Phalcon if it suits your needs, using the features offered by expressjs for example.
I would not choose one over the other based on performance.

zk vs gwt zk too many requests

Hi I am trying to compare the performance of zk and gwt.
In my comparision I cant write any javascript by myself if the framework itself converts some code into js its ok(like gwt) but I cant write js by myself
On writing code in the above way for almost anything done on browser a request is sent to the server in ZK.
Hence eventually if you compare the no of request sent by zk to server is too high as compared to gwt.
i would like to ask the following.
whose performance is better zk or gwt while ignoring the above.
if we dont ignore the above then is my conclusion that gwts performance is better than zk right ?
I know that there might be other parameters when comparing performance... but if the difference between requests are so high i cant really see zk beating gwt which some people have said on some forums
pls help
thanks
GWT and ZK are very different architecturally. GWT is client-centric so it sends less requests to the server. With GWT you can basically control everything by yourself. This on the otherhand means, the developer is responsible for handling server requests and asynchornouse data transfer between server and client. If you are an experienced web developer then the result could be great. If you are not then it could be pretty challenging and complex as there are some network and security issues you need to take care.
On the other hand, ZK is server-centric, it handles these server-client async communication for you. With ZK developers can focus more on the business logic without taking care of client-server issues. As the framework takes care of client-server talk, there are more requests by default. If you wish to minimize the request, you can probably follow their developer's guide to do some tuning.
IMO ZK and GWT are both matured framework. You can probably think about your project requirements and your experiences in Web development then choose the solution.
The previous posts are basiclly, but there are some features in zk that,I think, must be talked about.
Remember, every request is a zk-event, cos zk is completely event-based.
Client-Side Event-Handling
Zk allows you to implement client-side event-handling just as well as server-side,
which includes preventing zk from firing an event to the server.
You can simple manipulate the client objects in js as you can do it in Java on the
server-side or just do some post processing and and then...
Use Client-Side Event-Firing
Zk got that usefull js method zAu.send(zk.Event,int) that let's you send custom
or standart events to the server.
Deferrable Event-Listeners
Deferrable-events are queued at client-side, so you can minimize the number of
requests.
Stubonly
Stubonly is a way to make a component client-side only. But by now this is only
available for zk EE.
So, you can see, if you like, you can limit the requests to maybe the same amount of requests of GWT.
If it make sense or not depandce on you/your applycation. But I think you can say that zk is more powerfull than GWT.
You maybe interested in iZUML and defer rendering too.
ZK is server side focused, since GWT is all in the browser, so ZK needs much more ajax hits to the server to get js fragments, screen portions, etc. whereas GWT just hit the server at the beginning to download the js app (which will be cached in the client for ever) and whenever the app needs some data from the backend.
Said that, IMHO GWT should perform better since you dont need any sort of view logic being executed in the server (lighter servers), and there are less requests in the wire.
GWT and ZK are kind of different.
I've done some ZK projects and also some GWT projects. I didn't have performance issues in either cases,but I feel I need to write more code when I use GWT.
My experience from real world projects with two teams, one writing using the zk framework and the second using GWT. Identical UI projects having data served from the same data service layer. The zk team completed the project in one third of the time the GWT team consumed. Both projects deployed in production. Users were happy using either app. Finally we kept the zk version in production. Why? Simply because the maintenance of the zk app was so much faster and simple compared to GWT! Sorry GWT... Nice technology backed up by a giant but we will keep going with zk.

Resources