I have a little (maybe the answer could require a book) question about web services and server side programming.
But first, a little preamble.
Recently we have seen new kind of applications & games using some kind of real-time interaction with a database, or more generally, with other users. I'm talking about shared drawing canvas, games like this , or simple chats, or the Android app "a World of Photo", where in real time you see who is online, to share your photos, etc.
Now my question:
Are all these apps based on classic TCP client/server architectures or is there a way to make them in a simpler way, like a web platform like LAMP?
What I'm asking, in other words is:
Can PHP+MySQL (or JSP, or RoR, or any other server language) provide a way to make online users communicate in real time and share data? Is there a way to do that without the ugly and heavy mechanism of temporary tables?
Thank you! I hope I've been clear.
There is this crazy black magiccy thing called P2P (peer-to-peer) that makes all of this possible.
I don't know, but I don't think it will catch on.
8-D
EDIT: CRAP....I didn't see the date the question was posted.
I can't believe it. This is my third consecutive question that involves XHR Long Polling aka Comet programming. Daliz, what you want is possible, easy and been done by various websites using XHR Long Polling.
The concept: Normally, web browsers send a request to the server, server sends a response back and closes the connection to the browser. Instead of closing the connection at the end, Comet programming keeps the connection open. So, the connection between the browser and the server is still open. So, in simple terms, when we want to connect to Alice, we find the thread connecting to her browser and send the message to Alice.
Facebook chant uses the same concept. Please read This.
If your client is not a web browser but some web service, then it is more easy. Web services unlike web browsers have an address. So, client service calls the main service with a callback URL and registers to a particular event. When that event happens, like someone drawing something, main service will use the callback url of the client service to notify about that action.
On sharing data like Photos or another binary data: it is also possible as the input stream from one user is send to all other related users. So a simple String or a photo can be shared. But it also means the user on the receiving end of the photo will not have a message like "xxx has sent you a photo. Click here to download it". They will simply get a "Do you want to open or save this file" option.
Related
I want to create a server on one device and the changes I make on a certain website should be visible on other devices in real time, I don't want to cast the entire screen just the website.
Can anyone help me with that?
If you want really to use WebRTC to send something that appears in a web browser to another web client, you should see Canvas to peer connection.
Anyway, if various clients should be informed about an event via web, I suggest that you see Your first Web Progressive Application
Is it possible to communicate from a web browser(Loaded an HTM page from server) to an application running in the same server using AJAX. Need to send the request from browser using a button click and update the page with responses received from one another application running in the same server machine?
I am using HTML pages to create website and not using any PHP or ASP like server side scripting. In server machine data are manipulated using a C++ application.
I think you can use any sort of Javascript functions to do that. But you might need to use jQuery or similar frameworks to make your live easier. You might need to search for "Comet Programming" to know exactly how to do 2-way communication between client and server
Updated:
Well, this kind of stuff requires you to read a lot (if you have not already known). Basically, what you need is a server that can do long-polling (or eventsource, websockets). There are many open-source ones that might help you to get started. I can list a several good ones here. There are a lot more
http://www.ape-project.org/
http://cometd.org/
http://socket.io/
http://code.google.com/p/erlycomet/
http://faye.jcoglan.com/
So after you have the comet server up and running you will need to setup the client side (probably Javascript). For those listed projects, most of them come with the client side code to interact with the server (Except for erlycomet). Therefore, you can just use the examples provided and run a quick prototype. If you want to use your raspberry pi, you can use nodejs which provide a lot of ease for dealing with real-time communication (socket.io, faye). And lately, http://www.meteor.com/
I would think of the problem this way: you want to provide a web front end to an existing c++ application. To achieve this you need to think about how your web server communicates with your c++ application. Communication between the browser and web server can be thought of as a separate problem - as you say AJAX calls can be used, or maybe have a look at websockets.
Once you have your request in the web server you need to communicate it to the C++ application (and/or visa versa). This can be done a number of ways, e.g. sockets or RPC. I found this question here which has some good advice.
As mentioned here
https://github.com/blog/1174-auto-updating-comments
What is the technology behind this? If I've to add this feature in a Django powered web app, what should I use and study?
Looking at network tab it looks like they (at least with chrome) are using HTML5 Server Sent Events.
So practically the browser subscribes to a event stream and the web server just sends messages back.
I am not an expert but I guess on the server side you need to be able to keep an open connection that streams the events to the client.
I found an implementation of SSE for python here: https://github.com/niwibe/sse and a django implementation on top of that: https://github.com/niwibe/django-sse
I did not use them (yet) on any production so I suggest them only as study / poc material :)
I am working a real-time lighting control system.
User can turn on/off lights through web interface, but when another person turn on/off light switch manually the web interface should be updated immediately. That's the real-time goal I want.
The structure of the system is like this.
I have my own server at home, which control/monitor light status real-time. Django project is on my cloud server communicating with my home server real-time.
I have searched some similar posts and found many tools that confuse me a lot. All I want is to do long polling. User's browser will send http request to django server periodically(say 30s). If nothing comes up, server will hold the response until next one come. If there is an event, server will just reply immediately so real-time change at the browser side.
I know websocket is a better way, but I just want to make it work, the simpler the better. As long as it's reliable, compatible with existing browsers, performance is not a primary concern for me now. I can change it later if there is performance issue when scaling up. If it's possible, I still want to use Apache server to do this.
Does anyone knows a good tutorial or example that shows me how to implement it?
Thanks so much
I use Django 1.4, wsgi, Apache.
I have built a website in django framework. It has a lot of features such as blog, discussion forum, basically there are lots of ways users can interact. I have built a basic notification framework where a user gets notified when somebody comments on their blog, or answers their question in the forum.
Since the notifications are stored in db, new notifications are displayed only when a page refresh is done. I would like to make it real time using some push server using something like long polling technique.
I have come across NowJS which seems to be pretty handy for this, but in all the examples that are given I could not see any example where there was any interaction with the database. In all the cases there was some information sent by one client and it was displayed to one or more clients.
What I actually want to do is to call a function using NowJS, and make it go to sleep until a new notification is added in the database. When a new notifications comes in the server responds back with the notification and a new request is done immediately.
I can figure out all other parts except how to access the database from Node server that is used by NowJS. Any help or guidance is appreciated.
Either:
Have your node.js server make an http call to the Django server via something like a REST api to get info back
Google for a database connector for node.js - I found enough evidence for a MySQL one, and rumours of a PostgreSQL one. Note this won't get you access to the Django DB API, so you'll have to work out all your related queries and craft your SQL by hand (make sure Bobby Tables doesn't bother you: http://www.xkcd.com/327)
Re-implement the NowJS protocol so that you can write a django server for it, keeping the same JS client code on the clients... but then you may as wel.....
...use django-socketio http://blog.jupo.org/2011/08/13/real-time-web-apps-with-django-and-websockets/