Trying to create a "live" browser environment

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 1230 Views - Last Post: 17 August 2009 - 01:58 PM Rate Topic: -----

#1 BlackPhoenix  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 152
  • Joined: 11-July 09

Trying to create a "live" browser environment

Post icon  Posted 13 August 2009 - 04:20 PM

Hi,

I am trying to create a "live" browser environment, meaning if something happens on one client, all clients currently on that page will see the changes in as close to real time as possible.

What exactly are my options?

AJAX Short Polling

I have though about using AJAX with really short polling times (~50ms), but I'm not sure if a server can handle multiple clients doing 50 ms polling. That's 20 polls per second per client, which in a 100 client environment, means the server is being POLLED 2000 times every second. Don't forget this is just polling only, not even the fact that the server will be sending out replies to all of these clients.

Comet Programming

Another option was something called Comet, which I hope some of you are familiar with enough to give me some feedback. In short, Comet programming is the ability to have a server push data out to a client (or multiple clients) who are currently on a webpage without requiring them to poll. The benefits of this?:

Well the benefits are quite clear. With 100 clients, instead of having 2000 polls per second + response data being sent to each client, the server is only responsible for pushing data out to the client when it needs to (which in my case would STILL need to be in very short intervals (~50-100ms). Still, this eliminates polling, which helps a lot.

Conclusion

I don't know how to program a PHP server being able to push data out to clients, but I DO know how to integrate PHP with Javascript and XMLHttpRequest messages (AJAX), which is option 1.

Is it my BEST option tho? Can someone provide data to me about whether or not a server can take a beating from all the ajax polling?


[edit]
From thinking about what I just typed up, I realized that the actions will be taken place by the CLIENT first, then updated to the Server, and as SOON (as close to immediate as possible) the server is updated of these changes, it will put them in the database, which the clients will poll to update themselves. This logically means that Comet is NOT what I want in this particular application.

Please provide me with some feedback related to short-time AJAX Polling though.

This post has been edited by BlackPhoenix: 13 August 2009 - 04:28 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Trying to create a "live" browser environment

#2 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1137
  • View blog
  • Posts: 7,099
  • Joined: 07-September 06

Re: Trying to create a "live" browser environment

Posted 13 August 2009 - 05:23 PM

I would choose option 3.

Now, it is a bit more difficult, and require additional server allowed languages, but it will require less polling (polls only being made after something has been updated). This is the general idea:
First, create a Flash application that creates a socket connection with the server (this is where the additional server language comes into play - you need to make a socket server in something that is able to run constantly (Java, Python, C++, Ruby on Rails are all capable of doing this).
Then create a Flash to Javascript connection (so you can do events based on what the socket server sends out to everyone).
After that, create an Ajax posting (for comments and updating the page).

Once you have accomplished all of this you can go to making it work. You have Flash make a connection to the socket server when the page loads, and then have Flash and Javascript connect to eachother to allow for them to communicate (so Javascript, through Ajax, can update the page).
Once someone posts a reply send that through Ajax to a PHP page to be entered in the database. After the response text is recieved by the Ajax have Javascript tell Flash to send an "page updated" message to the socket server, which will be sent out to everyone who is viewing the same page. From there, the flash tells Javascript to send an Ajax call to the server to retrieve the update from the database and display it on the page.

Now, as you can probably tell, this is quite a complicated process, but there are advantages to using it. One (and probably the biggest) is that you are sending very little information to the server (only the socket server is in charge of updating things constantly (as people change page, etc.) the clients only make an ajax request to the server after they know there is something worth getting (which saves a lot of bandwidth in theory as it won't be sending all the response packets back and forth, all that is being sent around is things that have reason to be sent (if that makes any sense).
Was This Post Helpful? 0
  • +
  • -

#3 BlackPhoenix  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 152
  • Joined: 11-July 09

Re: Trying to create a "live" browser environment

Posted 13 August 2009 - 05:59 PM

Thanks for the reply betawar. I have actually tried to create applications and games using PHP and Flash once before, but failed miserably because I couldn't even pass 1 string back and forth between PHP and Flash (or Flash and MySQL). That, added to the fact that there are not many tutorials on the subject, and I was suddenly feeling too overwhelmed and in-over-my-head to continue.

I have spent some time in the past creating C++ socket servers, but I still don't understand how this could be used to interact with flash. How would the C++ run on the net? I'd rather avoid this entirely.


In fact, my actual application (which is a game) could be created entirely in Flash if I can find a way to learn how to get flash to retrieve data from a MySQL Database. The In-Browser Live Environment was a mere workaround for the fact that I can't figure out how to get PHP, MySQL Databases, and Flash working together!
Was This Post Helpful? 0
  • +
  • -

#4 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1002
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: Trying to create a "live" browser environment

Posted 14 August 2009 - 05:58 AM

This is fun, look into HTTP PUSH servers, that way you can PUSH messages out to your clients without having to get the client to do anything, fun stuff init :D

Alternatively, you can have a never ending PHP Script that will effectively emulate a HTTP PUSH server, it will basically check for updates, flush() (if required), sleep(), check for updates, flush() (if required), sleep(), etc, etc. That way it's all done server side and you don't have to initiate a new connection for each.

You just triggered a nice new idea for MageHTTP though, thanks! I'll be sure you license you a copy if you run a Windows environment ;)

This post has been edited by MageUK: 14 August 2009 - 06:00 AM

Was This Post Helpful? 0
  • +
  • -

#5 BlackPhoenix  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 152
  • Joined: 11-July 09

Re: Trying to create a "live" browser environment

Posted 14 August 2009 - 06:31 AM

View PostMageUK, on 14 Aug, 2009 - 04:58 AM, said:

This is fun, look into HTTP PUSH servers, that way you can PUSH messages out to your clients without having to get the client to do anything, fun stuff init :D

Alternatively, you can have a never ending PHP Script that will effectively emulate a HTTP PUSH server, it will basically check for updates, flush() (if required), sleep(), check for updates, flush() (if required), sleep(), etc, etc. That way it's all done server side and you don't have to initiate a new connection for each.

You just triggered a nice new idea for MageHTTP though, thanks! I'll be sure you license you a copy if you run a Windows environment ;)



Well best of luck to you :)

Is it difficult to integrate PHP and Flash? I can't find any good tutorials >_<
Basically hijacking my own topic.

I want to be able to allow Flash to work with a MySQL database, but PHP will be needed for some variable calculations, logging in to the Flash client, etc.... I Think.
Was This Post Helpful? 0
  • +
  • -

#6 BlackPhoenix  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 152
  • Joined: 11-July 09

Re: Trying to create a "live" browser environment

Posted 14 August 2009 - 10:31 AM

I think I could better decide my plan of attack if I understood something more clearly.

How is the position of a client in a networked/online game shown for everyone?

Does the client receive a coordinate from the server or database and then refresh it on the screen, and just refresh at extremely short intervals? (10-30ms)?

Anything else I should know about? I definitely have a plan, and I'm almost positive it will work!
Was This Post Helpful? 0
  • +
  • -

#7 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1002
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: Trying to create a "live" browser environment

Posted 14 August 2009 - 10:33 AM

Errr, I replied to this post...........

I said that you could initiate a request to a PHP script from Flash that will do data handling, no clue where it's gone.. :|

Each game's written differently, generally as soon as the server receives an update, it will immediately send it out to the rest of the clients that are connected.
Was This Post Helpful? 0
  • +
  • -

#8 BlackPhoenix  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 152
  • Joined: 11-July 09

Re: Trying to create a "live" browser environment

Posted 14 August 2009 - 11:35 AM

Synchronization of animations:

Ah yes, but what about handling animations. Let's say client1 finds out from the server thatclient2 is at 5,5, then at 5,4 then at 5,3 (falling). The client will be able to see (from refreshing) that the y position is dropping, but how does he know which state his legs (for example) are at during his falling?

Basically what I'm asking is, it's easy to get some quantifiable numbers from a server and display them, but how does client1 know to display the animations of client2?

Some pretty complex stuff!! Fun to think about!

This post has been edited by BlackPhoenix: 14 August 2009 - 11:37 AM

Was This Post Helpful? 0
  • +
  • -

#9 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1002
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: Trying to create a "live" browser environment

Posted 14 August 2009 - 12:24 PM

Well this is nothing that we can discuss on a global scale, how your game does this is completely up to you :)

You can either have it use it's own idea of animation (on each movement the legs alternate between left/right and change direction, etc) or you could have the server send back which animation/image it should show :)
Was This Post Helpful? 0
  • +
  • -

#10 BlackPhoenix  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 152
  • Joined: 11-July 09

Re: Trying to create a "live" browser environment

Posted 14 August 2009 - 09:10 PM

View PostMageUK, on 14 Aug, 2009 - 11:24 AM, said:

Well this is nothing that we can discuss on a global scale, how your game does this is completely up to you :)

You can either have it use it's own idea of animation (on each movement the legs alternate between left/right and change direction, etc) or you could have the server send back which animation/image it should show :)


Yea you are definitely correct, Mage.

Well I created a design sheet of 2 different approaches I can take. Which do you think will be the most effective (less strain on overall system, fastest response time/lowest latency) ?

I think "idea 2", only because even with a lower amount of queries from the socket server to the database, the server has to push to all clients as well.

IMG PROVIDED:

Posted Image

This post has been edited by BlackPhoenix: 14 August 2009 - 09:11 PM

Was This Post Helpful? 0
  • +
  • -

#11 Wimpy  Icon User is offline

  • R.I.P. ( Really Intelligent Person, right? )
  • member icon

Reputation: 159
  • View blog
  • Posts: 1,038
  • Joined: 02-May 09

Re: Trying to create a "live" browser environment

Posted 15 August 2009 - 02:37 PM

While talking about push servers, check out the APE Project: http://www.ape-project.org/ . :)


View PostMageUK, on 14 Aug, 2009 - 02:58 PM, said:

This is fun, look into HTTP PUSH servers, that way you can PUSH messages out to your clients without having to get the client to do anything, fun stuff init :D

Alternatively, you can have a never ending PHP Script that will effectively emulate a HTTP PUSH server, it will basically check for updates, flush() (if required), sleep(), check for updates, flush() (if required), sleep(), etc, etc. That way it's all done server side and you don't have to initiate a new connection for each.

You just triggered a nice new idea for MageHTTP though, thanks! I'll be sure you license you a copy if you run a Windows environment ;)

Was This Post Helpful? 0
  • +
  • -

#12 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1002
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: Trying to create a "live" browser environment

Posted 15 August 2009 - 02:48 PM

Mmm that isn't true PUSH though, it's just constantly requesting as far as I can see.
Was This Post Helpful? 0
  • +
  • -

#13 ShaneK  Icon User is offline

  • require_once("brain.php"); //Fatal error :/
  • member icon

Reputation: 240
  • View blog
  • Posts: 1,224
  • Joined: 10-May 09

Re: Trying to create a "live" browser environment

Posted 15 August 2009 - 03:07 PM

Wouldn't a server just using sleep() and flush() be using massive amounts of resources?

Yours,
Shane~
Was This Post Helpful? 0
  • +
  • -

#14 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1002
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: Trying to create a "live" browser environment

Posted 15 August 2009 - 04:03 PM

Not if it's a) not doing much and B) you manage memory correctly (freeing MySQL results blabla) :D
Was This Post Helpful? 0
  • +
  • -

#15 BlackPhoenix  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 152
  • Joined: 11-July 09

Re: Trying to create a "live" browser environment

Posted 16 August 2009 - 10:09 AM

So which of my methods is better? lol you guys started talking about APE, which I know about, but that wasn't really the issue :)

Should I have an infinitely looping socket server which is ALWAYS checking database for changes and ALWAYS pushing things out, or just have clients that are ALWAYS querying the database.

I really thought 2 would be the best option out of THOSE 2, but you guys don't seem to agree.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2