View Full Version : PHP sockets and Flash
01-27-2003, 06:11 PM
Hey, everyone. I've just been doing some research over at Flashkit.com and came across something I want to find out more about.
I develop Flash games as a hobby, and just recently bought a domain name and hosting package that allows me to use PHP code. Now I've figured out how to use PHP to interact with Flash to display high scores and the like, but what I really want to do is develop some multi-player games. What I'd heard until today is that this was not possible without having a dedicated machine running a special socket server, which I don't have through my shared-server plan.
I read today that it is indeed possible to have such a socket function with PHP. Is this true? I have checked my phpinfo() and it says sockets are enabled, even though my local safe mode setting is on (off in the master setting) Does anyone know how I would go about doing this?
Even if it is impossible to create real-time connections between players, is it possible to have a simulated one for turn-based games? Someone mentioned something about PHP 'polling' but having just started with PHP, I don't know what they mean.
Any help is greatly appreciated!
01-27-2003, 07:19 PM
i dunno aobut php polling... but sockets is fine, but might not work as its in safe mode...
01-29-2003, 11:27 AM
A turn-based game - chess, checkers, battelships, whatever - is not a problem - just keep track of who's turn it is and disallow moves for the other player.
If you want a real-time multi-player game then you'll have to make use of a socket-server - at least if you want to make it run smooth.
You could use a polling-scheme, as you state, where you send the local information of a player to the server and retrieve the information of the other players and update this in Flash, but that won't run as smooth as a socket-server: the latter can push information to Flash when it's necessary.
For PHP to act as a socket-server it must be compiled as a CGI. There are some examples on that in the documentation (http://www.php.net/manual). But a Java Servlet might be a better option for real-time multi-player games on the net...
01-29-2003, 04:55 PM
Hey, Explore. Thanks for the reply.
Apparently, sockets won't work for me as my host is unable to turn off the safe mode setting. Is it possible to run a Java/Perl socket server? If so, does anyone have a link to a good reference/tutorial?
I don't think I'll need a smooth connection for what I want to do, but I'd like to learn as much about it as possible.
How would the polling system work? Sorry, as I said before PHP is still new to me and I'm having a hard time making much sense out of the manual. Again, and resources/tuts would be great.
Thanks a million!
01-30-2003, 09:17 AM
What's your background then? 'cos Java and Perl are both more complex than PHP. If you unstand Java or Perl, then PHP should be a piece of cake.
If none of the above is true, I really advice checking out the PHP manual before diving into sockets and stuff... The manual is full of examples and there are a number of good PHP sites out there.
Run a query through Google (http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=php+sockets).
01-30-2003, 08:41 PM
I suppose I'm as well versed in Java/Perl as I am in PHP (meaning, not very at all) I'm still new to server-side scripting (and programming in general, for that matter) and am trying to get a handle on things one project at a time.
Building this kind of system would mean a very intense study of the language itself, which I would welcome. I just don't want to spend my time learning a language for a specific application only to find it can't do what another can (although I'd be happy to learn it, I'm the kind that likes to see results from their work/study)
I've spent a lot of time with manual already; all I could find about sockets was that they are similar to C sockets, and a reference to a Unix FAQ page. As I said, I am somewhat new to the programming side and need a bit of a more simplified reference. If this doesn't exist I may be in serious trouble. ;)
Thanks for reply, though!
01-30-2003, 10:16 PM
Just my two cents:
Sockets, judging from the little exposure I had to them, are quite complex. You won't find numerous "hello world"-tutorials which deal with sockets. And there's a lot of background stuff you have to know: Client-Server architecture, protocols, networking in general, synchronous/asynchronous communication and surely much more.
Please don't understand me that I'm about to disencourage you from digging deep into sockets, that's not my point. But if you are new to programming in general and expect results very soon, don't get frustrated if things turn out not be that easy as expected. Why don't get a good grip in programming first and then use your newly aquired skills to make your game run from a socket-server? A turn-based game can be both very challenging for the creator and very exciting for the user, why not start with that? (and don't forget the link for us once you've finished :) )
Apart from that, if you really want to do network programming, then is Java surely more suited than PHP (as explore already hinted at).
01-31-2003, 08:36 PM
Hey, mordred. Thanks for the reply.
It's funny, cause that's the same advice I always give a novice Flash programmer (not that I'm anything beyond that, but someone with none or less experience than me) 'Start small, get a grasp, bigger projects will be frustrating' Guess I should just take my own advice...
Funny thing though, turn based is what I wanted to do. Someone just gave me a good discription of how to do this using PHP to write to a text file (the elusive 'polling' idea; I assumed polling was a php function that I didn't know and couldn't find in the manual)
Anyhoo, thanks again to everyone who replied.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.