Flash Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignFlash Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 12th, 2001, 12:54 PM
TotalMonkey TotalMonkey is offline
Polynesian Monkey God
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2001
Location: Monkeytown, USA
Posts: 57 TotalMonkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 47 m 42 sec
Reputation Power: 7
Question Simulate "real-time" updates in Flash using PHP-sockets or some other method?

This is from a question I posted earlier in the PHP forum, but with a horrible subject! Also, this is sort-of a PHP question, but it really applies to integrating functionality into Flash projects, so that's why I put it here.

I'm using PHP with a Flash (swf) front-end, but I want to have a some-what "real-time" update of data provided to the front-end. So, I guess my real question is this: do I need to use the limited "sockets"-capabilities of PHP to connect with Flash, or should I just set my Flash to constantly poll my PHP program to simulate "real-time" access? I'm concerned about overloading my webserver with accesses, and honestly I'm not even sure if using sockets is really the way to go since I've never used them before. Any thoughts or ideas?

Thanks!
TotalMonkey!
__________________
"We're all - monkeys!" -- Jeffrey Goines, 12 Monkeys

Reply With Quote
  #2  
Old December 20th, 2001, 02:20 AM
DaveH DaveH is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Location: weeeee
Posts: 1 DaveH User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Flash Updates

Heres is a way to update flash in realtime. There is a working example with the tutorial. URL

Reply With Quote
  #3  
Old December 20th, 2001, 08:38 AM
TotalMonkey TotalMonkey is offline
Polynesian Monkey God
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2001
Location: Monkeytown, USA
Posts: 57 TotalMonkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 47 m 42 sec
Reputation Power: 7
Simulating "real-time" in Flash...

Well,...

I thank you, DaveH, but that's not really what I meant by simulating real-time. I guess I should clarify more. What I mean is to have a SWF that will constantly poll a DB or flat-file at regular intervals so that the SWF movie can be updated in what appears to be a "real-time" fashion, like for multiplayer games or chat and instant message clients and the like. I want users to have the impression that they are constantly connected without really have a persistent link, unless of course I can have a persistent link to the server that doesn't tie it up or overuse (read "abuse") it any way.

To be honest, I'm not sure there really is any way to do it, but I'm hoping that at least someone who knows about this kind of thing (with an understanding of both Flash and PHP and web servers in general) can tell whether it's possible or not.

Thanks,
TotalMonkey

Reply With Quote
  #4  
Old December 20th, 2001, 09:31 AM
dang65 dang65 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Location: Wilmslow, Cheshire
Posts: 255 dang65 User rank is Corporal (100 - 500 Reputation Level)dang65 User rank is Corporal (100 - 500 Reputation Level)dang65 User rank is Corporal (100 - 500 Reputation Level)dang65 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 12
If I understand you correctly, then the chat fla that was included in Flash 4's tutorials/samples did what you're asking (think Flash 5 works differently though). It had an action on one of its frames to submit a request to the server (could be any script or a flat file, whatever) and loaded the returned variables. I think the demo file came with an ASP script file, but you could easily adapt it to PHP of course.

When I got Flash 4 a couple of years ago I put that file up on a free server and it worked, but found it was 'locking up' quite regularly. And that was with no more than about 6 or 7 users at any one time. But that could well have been a crap server and any decent one should be able to manage a very high number of simultaneous hits without any problems.

Now, can I find the sample file anywhere? No. Must be out there somewhere though.

Reply With Quote
  #5  
Old December 20th, 2001, 09:53 AM
TotalMonkey TotalMonkey is offline
Polynesian Monkey God
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2001
Location: Monkeytown, USA
Posts: 57 TotalMonkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 47 m 42 sec
Reputation Power: 7
Quote:
Originally posted by dang65
If I understand you correctly, then the chat fla that was included in Flash 4's tutorials/samples did what you're asking (think Flash 5 works differently though). It had an action on one of its frames to submit a request to the server (could be any script or a flat file, whatever) and loaded the returned variables...

When I got Flash 4 a couple of years ago I put that file up on a free server and it worked, but found it was 'locking up' quite regularly. And that was with no more than about 6 or 7 users at any one time. But that could well have been a crap server and any decent one should be able to manage a very high number of simultaneous hits without any problems.


dang65,
I'm pretty sure I know which tutorial you're talking about, but I think that has an action that checks the flat-file every second or so, and if we're talking about 20-30 (or 200-300) connects, reads, and sends every second...

I'm wondering, is there's a better way to do that? Is there a way to do persistent links that don't cost so much in the way of server activity? Can sockets (or anything else I don't fully understand yet) solve this problem?

Thanks for the reply, dang65; I think we're getting somewhere.

TotalMonkey

Reply With Quote
  #6  
Old January 17th, 2002, 04:26 PM
TotalMonkey TotalMonkey is offline
Polynesian Monkey God
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2001
Location: Monkeytown, USA
Posts: 57 TotalMonkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 47 m 42 sec
Reputation Power: 7
Exclamation Found the answer...

I found the answer to this. Here is the text to a similar thread I have since erased (since it was pretty much a duplicate subject!)

Quote:
Originally posted by TotalMonkey
Re: How do you do "multiplayer" in Flash without hammering the server??

I have a flash file with a frame action that, after a couple frames (2 or 3) reads variables from a php program (which does a database read) and then "GoToAndPlay"s the first frame.

The problem is that this method casues the web server to seriously lag (big time, like 99% cpu and memory use). I realize that methods i've used are intrinsically taxing, but how else can I track the screen positions of two online users so that the movie can display accurate, up-to-date (to the half-second) data without such a tremendous hammering to the web server?

Can anyone help? Does this question belong in a different forum?



Thanks,
TotalMonkey!
... and ...
Quote:
Originally posted by TotalMonkey
Re: I found the answer...

I went to www.flashkit.com and asked my question there, and apparently the method I was using is (as I expected) not the preferred method for polling my PHP script. It looks like what I need to do is use "XML Socket Connections" to pass data back and forth in a "real-time" fashion.

These XML Socket Connections are implemented through a set of Flash 5 functions utilizing an "XMLSocket" object in Flash, and on the back-end using an (surprisingly enough) XML Socket server, which allows Flash to open up these socket connections and then (passively? actively?) "listen" to the server for "broadcast" messages. I'm in the process of researching these methods and technologies and have ordered the book recommended on the subject, "Flash Games Studio" from FriendsOfEd/Wrox publishing.
Again, sorry for the double post...

Enjoy!
TotalMonkey

Last edited by TotalMonkey : February 1st, 2002 at 12:48 PM.

Reply With Quote
  #7  
Old February 1st, 2002, 11:49 AM
JeffCT JeffCT is offline
PHP & Ruby Developer
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jan 2001
Posts: 1,437 JeffCT User rank is Lance Corporal (50 - 100 Reputation Level)JeffCT User rank is Lance Corporal (50 - 100 Reputation Level)JeffCT User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 5 h 36 m 40 sec
Reputation Power: 9
No you don't need to mess with sockets or any of that. Most PHP Flash Chat programs and live counters just use loadVariables() over and over to make HTTP calls to some PHP script. But then again it depends on what you're doing. If it's a small app then don't worry about it, if you want some huge multi-user application, then you would look into the XML sockets and what not.

Reply With Quote
  #8  
Old February 1st, 2002, 12:38 PM
TotalMonkey TotalMonkey is offline
Polynesian Monkey God
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2001
Location: Monkeytown, USA
Posts: 57 TotalMonkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 47 m 42 sec
Reputation Power: 7
Arrow Flash's LoadVariables[Num] vs. Sockets

I've discovered through experimentation and discussion with others that using LoadVars/LoadVarsNum with PHP just won't cut it. I have a machine setup on a LAN at home to act specifically as a web server, and the Flash-PHP test I tried cranked my CPU usage up to 99% and lagged both sides big-time -- that's with only one user/connection! So this is definitely not the way to go. (Add database accesses to that and you completely tie up the server.)

So, I asked around FlashKit and soon discovered that the most effective way to do this is to use Flash 5's XMLSocket object with a socket server on the server side (for best results - i.e. performance - built specifically for the Flash app you've built). As far as I understand, socket servers are just programs that allow persistant TCP or UDP connections to client programs.

Now, I'm no expert at socket programming, but there's quite a bit of info on the web about it. My next major concern was - what language to use? I've asked around and was told that C-based socket servers (when coded efficiently of course) typically have the best speed and performance, but I'm not too sure I can run executables from my host. A PHP-based socket server would do well for me, but the only responses to questions concerning tutorials or explanations have pointed me to the PHP manual. However, the only help the PHP manual provides for PHP socket programming is a non-working example and a *PHP does it the same as C*statement (which leads me to think that maybe I should just learn sockets in C). The user comments were somewhat helpful, but not exactly enough for a beginner.

So, that's my dilemma. I've bought an excellent Flash book called Flash Games Studio by friendsofed.com (bought it for less at Amazon.com), but it doesn't go into server programming, only Flash and ActionScript. I'm left with the realization that I'll probably have to learn to write a socket server in C, and maybe port that knowledge to PHP if it's worth it.

I'm open to discussion if anyone has comments, issues or questions. And by the way, thanks for the responses from DaveH, dang65, and JeffCT.

Thanks again,
TotalMonkey!

Reply With Quote
  #9  
Old February 1st, 2002, 04:11 PM
nathank000 nathank000 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Location: tennessee
Posts: 30 nathank000 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 31 m 8 sec
Reputation Power: 8
Post swish or generator?

monkey
have you looked at generator or swish?

everyone I know has taken the cheap route and used php to get the info from the dB, format it so flash can read it, and write a text file on the server. Flash then grabs the text file on a regular interval and updates the movie that way.

But i think that generator (if you can afford it) is the solution that would make the most effective use of the server processor and would eliminate as many possible problems too. Swis is the cgi based alternative to generator but i think that some of it's capabilities are limited.

as for socket programming- way over my noggin (for right now).
hope you find something!
__________________
with logic as our scripture and knowledge as our savior we will overcome any and all tests on our horizon

Reply With Quote
  #10  
Old February 1st, 2002, 04:20 PM
nathank000 nathank000 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Location: tennessee
Posts: 30 nathank000 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 31 m 8 sec
Reputation Power: 8
Lightbulb just found this on Webmonkey

just spotted this right after i replied- haven't had the chance to read it through so I am not sure if it is what you are looking for but the name sure sounds helpful!

have a look and let us know if it is of any relevance!

http://hotwired.lycos.com/webmonkey.../tutorial9.html

Reply With Quote
  #11  
Old February 1st, 2002, 04:21 PM
JeffCT JeffCT is offline
PHP & Ruby Developer
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jan 2001
Posts: 1,437 JeffCT User rank is Lance Corporal (50 - 100 Reputation Level)JeffCT User rank is Lance Corporal (50 - 100 Reputation Level)JeffCT User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 5 h 36 m 40 sec
Reputation Power: 9
TotalMonkey:

I would have to say I think something is definitely not right with your setup, and it doesn't have anything to do with using loadVariables(). I have used the loadVariables() method with dynamic Flash applications and gotten over 100 concurrent users simulataneously on minimal hardware (PII 400Mhz, 128MB RAM). You need to find the real bottleneck of your program and not immediately assume it is Flash, because think about it - via loadVariables() you are just making an HTTP connection over and over so if that were really the problem in itself, your same setup would shoot the CPU usage up to 99% if someone were just browsing a web page off of that server (which is essentially the same thing).

I have the same setup as you. I used one machine as a client machine and wrote a script to mimic someone using the flash frontend (send HTTP requests about every 5-7 seconds for each user). Another machine acted as the web server. I was able to get up to over 100 concurrent users numerous times with the server not at 99% usage.

I realize there are variables involved in setups and that there could always be a difference, but I am convinced that is not what is causing you to only be able to support 1 user and I have done over 100.

Check for bottlenecks in your code, mainly database issues if you use MySQL. There could be a missing indexes in your database, or something else. I wouldn't give up on loadVariables() just yet, I assure you that you can support Many concurrent users simulateously via that method.

What is your code like? If you are getting that poor of performance with 1 user, XML sockets aren't going to help much, that's not the bottleneck of your code.

Reply With Quote
  #12  
Old February 5th, 2002, 11:27 AM
JeffCT JeffCT is offline
PHP & Ruby Developer
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jan 2001
Posts: 1,437 JeffCT User rank is Lance Corporal (50 - 100 Reputation Level)JeffCT User rank is Lance Corporal (50 - 100 Reputation Level)JeffCT User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 5 h 36 m 40 sec
Reputation Power: 9
TotalMonkey:

Were you able to make any progress on this issue?

Reply With Quote
  #13  
Old February 5th, 2002, 01:22 PM
TotalMonkey TotalMonkey is offline
Polynesian Monkey God
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2001
Location: Monkeytown, USA
Posts: 57 TotalMonkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 47 m 42 sec
Reputation Power: 7
Well, yes and no...

There definitely a bottleneck between Flash and the database, but I think. I'm still analyzing the system, but if the database access is the problem then I've got a big problem.

Reply With Quote
  #14  
Old February 5th, 2002, 02:24 PM
JeffCT JeffCT is offline
PHP & Ruby Developer
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jan 2001
Posts: 1,437 JeffCT User rank is Lance Corporal (50 - 100 Reputation Level)JeffCT User rank is Lance Corporal (50 - 100 Reputation Level)JeffCT User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 5 h 36 m 40 sec
Reputation Power: 9
Hm. Well let me know of your progress. I'm absolutely positive though, that you can support many concurrent users with the loadVariables() method, it's really not all that slow.

Reply With Quote
  #15  
Old February 5th, 2002, 03:33 PM
TotalMonkey TotalMonkey is offline
Polynesian Monkey God
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2001
Location: Monkeytown, USA
Posts: 57 TotalMonkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 47 m 42 sec
Reputation Power: 7
I'm not at my home computer now, but I think that my performance issues arise from the fact that, in order to simulate a multi-user "realtime" environment (i.e. update position information for 2 simultaneous players fast enough to trick the eye into thinking that it's "realtime"), my Flash movie needs to check the database (actually select then update) 4 times per second (3 frame intervals at 12fps). So not only is each player (i.e. each independent Flash movie) hitting the webserver 4 times per second, the DB is also getting 4 I/Os per second (with 2 queries per hit)!
The problem is, that there's not really another way of "broadcasting" all player positions to all players quickly without using a socket server. This would alleviate the need to constantly hit a DB or flat file for random access (since each individual Flash movie would store the info broadcast by the socket server). HTTP just doesn't do what I need in terms of speed.

Reply With Quote