tags:

views:

176

answers:

5

I've been scouring Google to find out how I can make Flash bring at least two users together in an environment. What I've been trying to do is, for example: both users load http://example.com/myflashenvironment.html, and on that page is the same flashenv.swf file that they both see from two different computers. In the flashenv.swf there is a movieclip object that is draggable. I want to make it so if user 1 drags the movieclip then user 2 can see it being dragged, over the Internet in some kind of online type of deal. I've been trying to do it at runtime, like an online game.

I've been searching google and I've found things about sockets, but it's very hard to just jump right in when you are me. I've tried to figure out so far that I need a PHP file that creates a connects to my server with fsockopen, and then I need to create a socket? But then I don't know how to have user 1 write the (x, y) coordinates of the movieclip when he drags it and have user 2 automatically pick up those same coordinates.

And please believe me, I used this as a last resort to see if anyone knew what I am talking about. Google just isn't cutting it tonight.

+2  A: 

It sounds to me like you need to read up on how to actually use sockets. Once you understand how they work, how you should structure your program should become very clear. You could serialize a small object with whatever you want the other user to see (like a coordinate change, for example).

But nevermind that, PHP is not what you want. PHP is not made for this sort of thing. What you need is some kind of standalone server - you would have to roll your own using C++ or Java, for example. PHP is made for short requests - you can't run it as a server. Yes, it does have sockets, but they're also made for quick one-shot connections. You need something that is always running, I'm assuming.

You should check out some of the flash multiuser servers that are already made if you don't want to roll your own. Red5 is a free one, and SmartFoxServer is a more fully featured server, but it is not free (they do have a free version, but it only supports a few concurrent users).

ryeguy
I'm a PHP coder and sadly, ryeguy is right. You could definitely do a work around with flash communicating externally through external interface or XML to PHP to Database and have other users' flash checking repeatedly for changes but that's not a good solution.
jerebear
Here's a tute to help you get started http://www.devarticles.com/c/a/Flash/XML-Sockets-in-Flash/
jerebear
A: 

It is questionable (but not without precedence) to write and run a server in PHP. The suggested Java based solution fits better for your needs.

Csaba Kétszeri
A: 

If you are totally new to multi-user Flash, I recommend using SmartFox Server. It is very easy to use and there are many tutorials.

Iain
A: 

it is possible to create the socket server you want in php, but i don't really recommend it.

the difference to traditional php scripts is, you wouldn't run it like it's called over the browser, but a long-running (think infinite loop) cli-server-application (more like java)

simplified it works like this:

  1. php: the script starts and listens for incoming request
  2. flash: the flash app is started and connects to the server
  3. php: the connection (from 2) is stored in an array
  4. flash: now if the user moves his movieclip, the coordinates are sent to the script
  5. php: data arrives (the coordinates from 4). now you loop through all connections and ...
  6. ... send the data to all the other movieclips
  7. flash: if data (from 6) arrives, update the mc position accordingly
  8. if the flash connection is terminated, remove it from the array

the problems: - php is not really well suited for this - you still have to learn about sockets. there are lots of tutorials on this topic, but most of them cover only single connections. - depending on where you host it, your provider might not support long-running php-cli apps

Schnalle
A: 

No need to write your own server, use sockets or other complicated and time-consuming techniques.

Adobe has created the shared object class for exactly that purpose. You need to have a server running Flash Media Server (or equivalent) and use remote shared objects.

evilpenguin