I just saw the McDonald's commercial which I have linked to below and I would like to try developing something similar for a festival. We have been talking about making a game in which the user has to use their iPhone and something like what McDonald's has done would be great.
My question is if anyone have an idea how I can send the data and what technology they might have used? I imagine making two websites. One on which the game itself is shown and one which is the controller but how would I make sure that the data is sent and handled fast enough?
I am familiar with JavaScript and PHP. I have been working a bit with flash and ActionScript and I am wondering if that might be best for the game (obviously not the controller)
You can see the McDonald's commercial on the link below. Basically, the user visits a webpage which is the controller and then they are able to play the ping-pong game on the big screen.
Any ideas and brainstorming on how to do this is welcome.
Watch the McDonald's Pick n Play commercial here.
Just use WebSockets. The problem with them is browser support and supporting older browsers / platforms.
To handle this there are various abstractions. I would personally recommend socket.io A solid abstraction that relies on node.js. Has a range of fallbacks (including COMET and Flash). Whilst your at it, you might want to looking into using node for realtime applications (it's great!)
I would create a socket server that hosts the game (socket TCP/IP connection). The purpose of the socket server application would be to listen for connections, wait for 2 players, start the game, decide who wins and sett-era (it could also have some queue of players that will play next and inform the players where they are in the queue).
Now, how do we establish a connection from the website to that socket server?
I wouldn't use WebSockets because it's not widely supported at the moment, disabled by default in FireFox and IE does not have it implemented yet (AFAIK).
Now you have to decide, do you want to do the website in Flash or HTML. You could even use hybrid of both. For example:
Hybrid:
Use the Flash application on the controller website to act as the communicator between JavaScript and the server. When Flash retrieves data from the socket server then it will make JavaScript take care of the retrieved command. E.g. move pad up. (I use that method for my online chat application and it works like a charm).
Flash only:
Use pure Flash application as the controller and communicator to the socket server.
Voila! You have something similar to the MacDonalds game.
I hope my answer is clear enough and feel free to comment if some of my statements are wrong.
In my view, This is what I would go for :
A small client app that will be downloaded when connected to the website.Considering it in mobile platform, java app preferably. Alternative is flash, which is also suitable, but if graphics is not our aim then I suppose better hold it off.
A server to provide real time connections to the users one-at-a-time. (As shown in video). This is the actual pain for all the games out there. I would go looking for one of these projects as platforms:
http://opensource.adobe.com/wiki/display/blazeds/BlazeDS
http://www.smartfoxserver.com/
http://www.cubeia.org/
http://appengine.google.com/
Besides that, ideas - I would have liked if it was multi player (there was quite a crowd), but that would have meant at least person winning every game & more of free give aways for them.
As alternative can be COMET a web application model in which a long-held HTTP request allows a web server to push data to a browser, without the browser explicitly requesting it
have a look here: Comet
Related
I have been in search of making live websites by using PHP. (COMET) I have been searching for a very long time already. (around a month) I have even checked some PHP chat scripts and used on my webserver, but I had some problems on most of them. (will be explained)
So far, most of the people tells the same thing: PHP isn't the best language could be used with COMET. The chat/comet examples are hacky at best.
I am asking this because, I want to have some features on my websites, like allow logged in people to chat with each other. That is where I need an alive connection to PHP pages. I am also planning on making a browser based game, and an alive connection will still be a must!
AJAX was a rare thing 2 years ago, shined with Facebook. Now pretty much everyone uses it, and it became a standard on web development. Now, the COMET based websites are growing. Youtube, Google+, Facebook, EA's Battlelog and such. I believe I should learn how to use it.
Okay, here are my questions. (Some of the information at below are the ones I gathered while searching on Google. Not sure if they're correct or not.)
Some languages like Python have special web servers designed for this job. I believe one of them is called Tornado Web Server. Developed and configured to simulate thousands of alive connections. I believe there is no such option in Appserv, but some people told NGINX can handle it with a decent configuration. Is it true? What configurations should be made? Is there any PHP web servers for this job?
Some of the most suggested things are:
a. Using APE.
b. Using Socket.IO
c. Node.js
Is there any way we can use them with PHP? Which one is the most promising? Could you give some guidance on them? Is there anything else than these?
I have used a comet chat script. Basically, you kept querying database and output the result with flush() to browser by sleeping it with usleep() in a loop. (This one became hard to understand so I will provide a quick code)
while(true)
{
// query database
// output the result
// flush the browser
// sleep for few seconds to lower cpu load
}
usleep() function basically destroyed my web server on Windows based operating systems. Is it normal to rely on usleep() on comet applications which runs on windows based OS? I mean, is there even a way to "sleep" PHP scripts? No matter what I do, CPU load goes to %100 on both WIN and UNIX servers.
Is PHP "really" that weak on this area? Should I give up with PHP and focus on other languages? If so, which language would you suggest? (That language should be promising. For example, there is no much use of AS3 after HTML5 addition, and AS3 is more likely to die soon while JS shines.)
What is WebSync? Can it be used with PHP?
Please bear in mind that I need to use COMET to make following applications:
A chat script, where logged in players will be able to chat eachother.
A browser based game. I already use JSON/AJAX and things like that when coding, but to receive opponents steps, I should pull the data, so an alive connection is needed. (Don't imagine advanced games, I am speaking about games like chess at best.)
I would appreciate if you can give me a short guidance. After all, I have been getting confused day by day since there are SO MANY random articles on internet. People even call setInterval() as COMET, so it is a complete mess.
There needs to be some clarification here. What you're looking for is not language specific per se. If you wanted to achieve the comet functionality with PHP you'd be relying on the Web Server (e.g Apache) to do the HTTP streaming. Also you need to understand that this is not supported in HTTP versions prior to HTTP/1.1. With that said, if you want to have a non-blocking event based web server, you're better off looking at Tornado and Node as suggested.
Comet is a programming technique that enables web servers to send data to the client without having any need for the client to request it This technique will produce more responsive applications than classic AJAX The user must create a request (for example by clicking on a link) or a periodic AJAX request must happen in order to get new data fro the server.
but it's create lots of traffic on your web server. If you want to build chat application in PHP use pusher which is a third party service and easy to use.
here is a link for pusher https://pusher.com/tutorials/realtime_chat_widget
the second suggestion is use ratchet for creating a chat application.
here is link for ratchet http://socketo.me/docs/hello-world
i hope it will help you
Short task description: I want one signed in user to be able to send an instant short plain text message to another signed in user. The solution needs to be easily scalable and not too resource demandinng in terms of bandwidth and server load (and $$).
The first idea was do client polling but this idea was quickly abandoned since it didn't meet scalability requirement. So, after that I went into research and came accross a number of concepts including sockets, node.js, xmpp. The amount of information is a bit overwhelming, so I was hoping for some advice to point me in the right directions. Hopefully something with readily available hosting solutions.
#epascarello:
thanks for quick response. I did, but not in detail. Before going in-depth into any technology, I want to be know that this is actually what I need.
Most of the examples concetnrate on instant chat but my requirements are somewhat different. I don't need every signed in user to see a message, but only one particular user, for whom it was meant, while there can be, say, 100 000 users logged in...
#Saeed Neamati:
thanks! Yes, I pretty much understand the two client-server communication options and have come to the conclutions that the pulling is a no-go. What I am trying to find now is the most scalable (that's the main prerequisite) and (hopefully) easy to implement push option. For instance, the socket option is relatively easy but it seems like it's not going to scale well due to server overload (or am I wrong). The node.js (at least by concept description) should be better at that, but I wanted to get some confirmation to this assumption. With xmpp - I'm not even sure how relevant it is to my task and how to approach it.
#andyuk:
Andy thanks, yes socket.io is also something that I came accross while doing research. As far as I understand it requires a server module that needs to run on a host. Do you know if possible to run on any server or do I need to look for a specialized hosting company? THe socket.io site for some reason doesn't work on my PC (neither IE or FF).
Did you look at the source code of nodejs chat.?
Look, you only have two options for client-server communication. Either client starts a request (an HTTP request on the web), which is called pull model (like client pulls the request out of the server), and server responds to that, or server starts a response directly without receiving any request (an HTTP response on the web), which is called push model (like the server pushes the data out to the client).
What you described as polling is actually the pull model, and indeed it takes lots of resources from the server.
But on the other hand, when you want to use push model, your server should know the client. In other words, we know that HTTP (based on TCP/IP) is a stateless protocol, which means that after each request, your connection is closed, and server loses you and forgets about you.
If you want the server to know the client, you should keep the connection open. This is usually done via some HTTP headers like Keep-Alive and Connection.
But to do that you should read Comet Programming. However, this reduces your scalability, because more connections are kept open for a one-to-one map between connection and client (To understand this better, you can think of connections as doors of the server. The more you occupy the door as a client, the less other clients can use it).
Checkout socket.io. If web sockets isn't supported by the browser it will fallback to the next best transport technology.
There is even a chat example included in the source code.
As for your concerns about scalability, node.js is perfect for this due to it's event driven, non-blocking nature. Handling many open connections is one of Node's real strengths.
Plurk uses Node.js for their real time chat features and they support 100k+ users.
The challenge I'm facing is simulating a communication channel between two users of a website (e.g. gaming site), by using solely the technologies mentioned in the title.
Recently I've developed an online chess website where, the idea behind which was to give users the chance to play "live" matches too, not just lengthy games where you would make a move, then come back in 1-15 days to see if your opponent has responded. And the way this game engine works implies sending asynchronous requests to the server, both to update the info related to the game (in case you make a move), but also to verify if anything has changed (if you are waiting for the opponent to move).
To better explain this... the player whose turn it is (the browser of course) sends an async. request to update the game info, exactly when he makes his move. Meanwhile, the opponent sends PERIODIC requests, "asking" if anything has changed. If anything does change, the roles switch after the board updates.
Timers are behind the functionality of the engine, so my question to you is this: How would you go about simulating a com channel between two players, while trying not to put too much stress on the server, but also having games update as fast as possible, in order to maintain the "live" feeling to it. This is most important in 1 minute games (one of the available categories). Because in that case, requests NEED to take place VERY often (at least 1 second). But server responses could delay, there would be much stress on the server when having hundreds of games available at the same time etc... so you see my problem.
I look forward to hearing from you guys and picking your brain if you have any good ideas :)
Cheers!
Andrei
PS: In case you want to try it, the name is e-chess960.com
you would want to builds a socket server. node.js would be a good javascript based library to use for a socket server. each client would create a socket connection to the socket server, then when a client sends a message to the socket server, the socket server could immediately send the message back out to its subscribers without having to store it anywhere.
socket servers require socket access, which usually requires a vps instead of a shared server.
to make the solution work, you would require that the clients have the ability to create socket connections to your server. some browsers already can as part of html5, but not all yet. you could also use Flash as a way to create a socket connection.
What you actually want is not pulling the server every second, but instead keep a connection open and use the observer-pattern to distribute updates to the specific clients (in other words: push instead of pull). That way, your server resources will not get swamped by a new connection for every second and every client. A library to accomplish that is the Comet Library. Check out this nice tutorial for a sample application.
I am developing a non-real time browser RPG game (think Kingdom of Loathing) which would be played from within a Flash app. At first I just wanted to make the communication with server using simply URLLoader to tell PHP what I am doing, and using $_SESSION to store data needed in-between request.
I wonder if it wouldn't be better to base it on a socket connection, an app residing on a server written in Java or Python. The problem is I have never ever written such an app so I have no idea how much I'd have to "shift" my thoughts from simple responding do request (like PHP) to continuously working application. I won't hide I am also concerned about the memory and CPU usage of such Server app, when for example there would be hundreds of users connected. I've done some research.
I have tried to do some research, but thanks to my nil knowledge on the sockets subject I haven't found anything helpful. So, considering the fact I don't need real time data exchange, will it be wise to develop the server side part as socket server, not in plain ol' PHP?
Since your game isn't something that's working in realtime you probably don't need to go down the socket route, though it's certainly a viable option. The nice thing about sockets is that updates would be instant without requiring page refresh (or server poll), so you're right to at least consider it.
If you do want to do a more real-time server setup, you might consider using something like Electroserver - this abstracts out much of the setup for you so you don't have to write your own server from scratch, plus it's free up to a certain number of concurrent users if I recall correctly.
Finally, a third option you have is a modified POST approach using AMF. Look into AMFPHP, it lets you call methods on a PHP back-end directly from your flash application. A little bit faster and easier than simply using POST stuff, but not quite as seamless as a socket connection or a specifically built gaming server.
Lots of options out there, it sounds like you are aware of this and kudos for trying to come up with the best approach rather than just rolling with what you know! I hope this helps, let me know if you have any questions.
Here's a link to Electroserver - http://www.electro-server.com/
I am interested in a really good way of doing instant messaging like meebo and facebook and myspace all have, also for notifications on a page. Example on my site now, when a user receives a new mail message, photo comment, profile comment, friend request, some other things, they will receive a notification message and link on the page they are on using jQuery and AJAX.
I believe on a large scale that this is not the best way to do it though as my jquery code will have to basically run a PHP script to query the mysql table every 30 seconds or so for every user who has the page open with this script running. I would like to eventually add in some sort of instant messaging like facebook has in a chat bar at the bottom of the screen if I can find out an efficient way of doing it.
I have heard the terms Comet and HTML5 WebSockets but I am not sure if these are the solutions I should be looking at for such a feature? I would like to keep bandwidth at a minimum and running a query every few seconds does not seem very efficient on a high traffic site.
If you know some good solutions, please explain how they work a little bit please
You're looking for a "comet" server. Since you're talking PHP, your best solution would be a SaaS solution, such as WebSync On-Demand, since PHP has issues with scaling when it comes to large numbers of concurrent connections being held open. See also this question.
I think Facebook uses XMPP for their chat, so have a look at it.
XMPP is
an open technology for real-time communication, which powers a wide range of applications including instant messaging, presence, multi-party chat, voice and video calls, collaboration, lightweight middleware, content syndication, and generalized routing of XML data.
You'd install a separate server to handle messaging and in your app you'd implement a client with one of the available libraries.
Could you have a shared message queue that ajax can query? Maybe its a php script that stores a majority of the message in memcached (and possibly write to db in case of failure).
Not sure, but curious to hear other solutions ...
The basic problem is that you need to implement a Comet server (ie implement Server Push). The standard web hosts and apache don't readily allow you to do this easily. Another hosted solution (apart from Web Sync) is Goldfish Server. Currently free.