A Flash Developer Resource Site

Page 1 of 15 1234511 ... LastLast
Results 1 to 20 of 284

Thread: The Grand Multiplayer Thread

  1. #1
    Gross Pecululatarian Ed Mack's Avatar
    Join Date
    Dec 2001
    Location
    UK
    Posts
    2,954

    The Grand Multiplayer Thread

    Well, you asked and you get.

    I'll start with the basics and explain a bit.

    There are two main ways of creating a multiplayer Flash game. All the ways require knowledge of another programming/scripting language (I'm not including the MM server, too expensive) and are not for beginners. Making a multiplayer game requires knowledge about a lot of different things, quite often you will need to know SQL (Structured Query Language) to store stuff in databases as well as your other language. Anyway, the two main ways to implement a multiplayer flash game are

    Polling
    This is the slower method, and not ideal for multiplayer games. This way, you create some server side scripts (in languages such as PHP, ASP, Perl, other CGI languages). Because of this, it is cheaper as most paid hosts allow some for of scripting.

    This script must accept input in the form of variables in the query-string, like myscript.php?name=edmack&score=5 or via http POST (if you've made a form before you will understand this). The script must output plain text in the same form for flash to create variables from it. An example would be: score1=edmack&score2=Fred&score3=kim

    Your flash script should do something along the lines of this to send your details, and add the variables it gets in response:

    loadVariables("myscript.php?name="+myname+"&score= "+myscore+", this, GET);

    This sends the variables
    name = myname (var from flash)
    score = myscore (var from flash)

    Sockets
    This is the fastest and best method. It requires that you have some sort of server sitting listening on some computer. This is usually a program of some kind, and typically requires more programming knowledge than the polling method. This can be acheived with Java, PHP (requires uncommon special settings), C, C++, Visual Basic, Python, Perl, and just about any other programming language.

    The reason sockets are far superior to the polling method is that it is almost like a piece of tube is held on end by both sides, the client (Flash) and the server (whatever). At any time you can send text down this tube, and the server will know it's from you, and be able to quickly send stuff back. This is unlike the polling method, where you have to connect and disconnect to the HTTP server every time. An added advantage of the socket option is that the server will know when you disconnect, but with the HTTP option it will just have to pronounce you dead after X amount of seconds have passed.

    I've included a simple example of a socket based game (it uses the free CommServer from a brilliant site www.moock.org . They offer an excelent server called Unity which is like the shell of a house, you just create the rooms... check it out if you know java).

    http://www.koyote.dk/flash_files/move_ball_multi.zip

    Feel free to post links, info or questions. I'll try to check in every now and again.

  2. #2
    Member
    Join Date
    Dec 2002
    Posts
    58

    Unity....

    Hey Ed,

    Whats Happening? I havent been on for a long time (i think)! Ummm.....i was wondering, do you know about Unity? I tried using the example you posted with the unity server, but it just doesnt seem to work Do you know how to make objects and have them show up on the other peoples computer while they are moving? Also, do you know howto create Channels? Sorry if i asked WAY TOO MUCH!

    Thanks!
    If you are interested in a postition for making an RPG like Diablo in Flash, contact us at flashrpgprogrammer@yahoo.com

  3. #3
    Senior Member
    Join Date
    Mar 2000
    Location
    Canada
    Posts
    133
    Great sticky Ed Mack.

    Personally I have had great success with the Polling solution.

    This solution is great for turn-based games, board games, or games that do not require a continuous connection the server. I would reccommend connecting to the server every 5+ seconds. I have found that less then 5 seconds may stun your server.

    More Information:
    http://www.ultrashock.com/tutorials/...multiuser.html - Ultrashock Multi-user Tutorial

    Example:
    http://www.rocketsnail.com/chat/penguin/ - Penguin Chat

    Once again "this is not for beginners". I would like to encourage you to partner with a programmer that understands server side scripting.

    I hope this was helpful.

    rsnail

  4. #4
    Senior Member SlizerNet's Avatar
    Join Date
    Aug 2002
    Posts
    276
    I am very good at VB and have currently used ASP with my flash mutli player games. I made an multi-user chatting system when each use can walk around and chat, but i found even tho it was running as fast as possible, it was just too slow.

    I would like to create a game using sockets. I have recently been learning visual basic creating applications in MS visual studio. Are there any tutorials showing me how to connect to a server etc?

    It is possible to insert a flash object in a VB app and communicate in realtime between the two when the app is running.

  5. #5
    Junior Member
    Join Date
    Jan 2003
    Posts
    29
    Sure can =)

    In vb, start a new project. Then, go under the project menu and select components. In there place a checkmark next to the Shockwave Flash object. This will add another icon to your box on the left hand side. You can now insert a flash movie by creating it like any other control.

    There are 2 ways to script between vb and flash. 1) vb simply pulling or doing things to the flash movie, 2) is flash telling vb to do something.

    Example of 1
    http://www.macromedia.com/support/fl...hflash_03.html
    All of these scripting methods can be used. VB can tell a movie to goto a frame, do a loadmovie, and even change a variables value.

    Example of 2
    Flash has a wonderful thing called an fscommand. VB will run an event when it recieves one of these commands. So flash could do:
    FScommand("showSave")
    and when vb gets the fscommand showSave it could popup a commonDialog control to save whatever.

    These methods could be used to give flash multiplayer capabilities using vb's winsock control. Or to do multiplayer you could have a flash movie connect to a vb server using sockets =D

    brain is exausted... must stop typing... need more info with vb/flash im your man

    Nugget
    xMCNUGGETx

  6. #6
    Pillow Daddy m_andrews808's Avatar
    Join Date
    May 2001
    Location
    London England
    Posts
    924
    Ello Ed

    great thread, this topic to a degree always seemed to be shrowded in mystery. Maybe you could help me with my problem? I've downloaded CommServer from Moock.org, and uploaded the relevent files to a directory in my domain. Now I'm having trouble getting the thing up and running. According to the readme.txt supplied with the files I need to have either JDK or JRE 1.0+ installed on the server and the ability to run java programs (I have emailed my hosts to ask if the server meets these requirements and they're yet to get back to me).

    My problem though is getting CommServer to run. The readme file says I need to navigate to the directory containing the CommServer files and start CommServer by typing:

    "java CommServer [port]"

    where [port] is the port CommServer will use. When I tried to do this I go this error message:

    500 JAVA not understood.

    does this mean my host doesn't have java on thier server?
    My hosts run Unix servers, would the command be the same as a Window server?
    If I can't use a Java based socket server, is there one based on a different language that might be more successful?

    Sorry to drone on a bit, but I really want to get this working!

    Thanks
    m_andrews808


  7. #7
    Senior Member
    Join Date
    Jun 2000
    Posts
    896

    More examples

    Here are two open-source multiplayer Flash games (pool and a puzzle game) and two open-source chats:
    http://www.electrotank.com/ElectroServer/
    Look for the 'examples' section.

    Here is one more open-source multiplayer Flash game. This one is real-time:
    http://www.gamebook.net
    Scroll to the bottom and look for the maze link.

    All of these examples use ElectroServer which is a socket-server found at the first link.

  8. #8
    Senior Member SlizerNet's Avatar
    Join Date
    Aug 2002
    Posts
    276
    Originally posted by xMCNUGGETx2
    Sure can =)

    In vb, start a new project. Then, go under the project menu and select components. In there place a checkmark next to the Shockwave Flash object. This will add another icon to your box on the left hand side. You can now insert a flash movie by creating it like any other control.

    There are 2 ways to script between vb and flash. 1) vb simply pulling or doing things to the flash movie, 2) is flash telling vb to do something.

    Example of 1
    http://www.macromedia.com/support/fl...hflash_03.html
    All of these scripting methods can be used. VB can tell a movie to goto a frame, do a loadmovie, and even change a variables value.

    Example of 2
    Flash has a wonderful thing called an fscommand. VB will run an event when it recieves one of these commands. So flash could do:
    FScommand("showSave")
    and when vb gets the fscommand showSave it could popup a commonDialog control to save whatever.

    These methods could be used to give flash multiplayer capabilities using vb's winsock control. Or to do multiplayer you could have a flash movie connect to a vb server using sockets =D

    brain is exausted... must stop typing... need more info with vb/flash im your man

    Nugget

    I've gotton that far and mastered using FS commands but i need info on sockets etc.
    Last edited by SlizerNet; 02-06-2003 at 03:37 PM.

  9. #9
    Senior Member
    Join Date
    Jun 2000
    Posts
    896

    General information

    Here is a link to short but informative thread that I started sevreal weeks ago. It contains some general socket-server information that would be informative to developers who have never used them before.

    http://www.flashkit.com/board/showth...hreadid=412184

  10. #10
    SaphuA mosterdfles_flash's Avatar
    Join Date
    Jan 2002
    Location
    Tha Couch
    Posts
    935

    Cool

    Thanks for another cool sticky

    I was just wondering on how to make a server on my pc... So that the multiplayer games goes through the pc and not through a free webhost...

    If I'm right... this is possible
    'How Art Is The Visual While We’re Artificial…'

    Mail & MSN
    My Not Finisched Page!
    Nick: SaphuA

  11. #11
    Senior Member
    Join Date
    Jun 2000
    Posts
    896
    mosterdfles_flash,

    Here are the basics of doing just that:
    As you probably know, all Flash needs to know in order to connect to a socket-server is the ip of the server and the port. Well, when you use a socket-server that will install on your own PC, like ElectroServer, then you just start it up on some port. When you connect to the Internet find out your IP address. You can then give this IP address and port to anyone else that you know and they can connect to the version of ElectroServer (or another socket-server) running on your PC.

    The downsides:
    1.) If you are behind a router (like for cable or DSL Internet, or at an office) then the router has the IP. When a connection request comes in from the Internet, the router doesn't know which computer to forward it to. So you have do some port forwarding (I think that's what it is called) on your router. Your router should have an admin tool to let you do that. Each sub-computer connected to your router has an internal network IP. You should forward the port that the socket-server is using to your computer IP. Then things should work for you!

    2.) You have setup a socket-server, not a file server. As you probably know, Flash can only connect to a server on its own domain. So you can't put a SWF in a web page on www.imakeflashgames.com and have it connect to your personal server. In order for a SWF file to connect to your socket-server either: a.) it must come from your own machine, or b.) It must come from the hard drive from another person. The cross-domain security restriction doesn't work when working directly off of the hard drive. So you can have people download your game to their comptuers and then it would work. There is a "c." option too, c.) Actually run a file server on your computer too. That way you can also serve up the SWF file and then it *can* be used in a web page. But I don't have any suggestions on how to accomplish that.

    In the Electrotank early days, about 2 years ago, I hosted ElectroServer on a computer from my apartment. A friend help me set up apache server on it so that it could also serve up some SWF files. It worked like a charm for several months before we bought a real server at an ISP.

  12. #12
    Gross Pecululatarian Ed Mack's Avatar
    Join Date
    Dec 2001
    Location
    UK
    Posts
    2,954
    Originally posted by m_andrews808
    My problem though is getting CommServer to run. The readme file says I need to navigate to the directory containing the CommServer files and start CommServer by typing:

    "java CommServer [port]"

    where [port] is the port CommServer will use. When I tried to do this I go this error message:

    500 JAVA not understood.
    Are you by any chance typing that command into an ftp connection?

    You need to connect via a terminal program.

    Also, *nixs are CaSE SenSitive. "java" != "Java" ect... Type your commands in lowercase (though, you need to use the correct name of the class file, "CommServer"). So type:

    java CommServer 9999 [hit return]

    And it should work.

  13. #13
    Pillow Daddy m_andrews808's Avatar
    Join Date
    May 2001
    Location
    London England
    Posts
    924
    Thanks for the reply, but unfortunatly my host doesn't have JDK or JRE so its no go. Only way I can do it is to turn my own computer into a server and install the necessary on there


  14. #14
    Gross Pecululatarian Ed Mack's Avatar
    Join Date
    Dec 2001
    Location
    UK
    Posts
    2,954

    Re: Unity....

    Originally posted by rpgprogrammer
    Hey Ed,

    Whats Happening? I havent been on for a long time (i think)! Ummm.....i was wondering, do you know about Unity? I tried using the example you posted with the unity server, but it just doesnt seem to work Do you know how to make objects and have them show up on the other peoples computer while they are moving? Also, do you know howto create Channels? Sorry if i asked WAY TOO MUCH!

    Thanks!
    The example I posted will only work with CommServer.

    Unity has what you call "channels", only they are called rooms in unity.

    Look into the RoomInstances.xml file to see the layout of the rooms. The <defaultroom> portion is the room the client is put into upon connection. This is normally "DispatcherRoom", which allows the user to select a room they want to goto via sending a string like this:

    <message type="requestRoom"><ROOMID>myroom</ROOMID></message>

    Creating objects and displaying them is something that can be done many ways. Check my example fla for how I did it. It requires a good bit of logic programming. Basically, when someone enters, they broadcast their name to everyone, along with coordinates ect.. and all the other clients add that person, then broadcast their details (there must be checking in the clients that they don't add the same person twice, I acheived this with an object holding all the clients).

    Then, when they want to move, the client broadcasts its distination, and all the clients move their movieclip of that player.

    That only works with simple games. Wehn you have complicated levels, and pathfinding comes into play you get a headache of people moving, and one player will send their path, someone else does the same and then they collide. It's better to do pathfinding serverside, especially when using a fast language like java

  15. #15
    Gross Pecululatarian Ed Mack's Avatar
    Join Date
    Dec 2001
    Location
    UK
    Posts
    2,954
    Originally posted by m_andrews808
    Thanks for the reply, but unfortunatly my host doesn't have JDK or JRE so its no go. Only way I can do it is to turn my own computer into a server and install the necessary on there
    Ask your host why they removed java, as it's normally installed on unix machines. The worst you could do would be to remove all your own files!

  16. #16
    Pillow Daddy m_andrews808's Avatar
    Join Date
    May 2001
    Location
    London England
    Posts
    924
    heh..... ...he....heh.... don't say that


  17. #17
    Junior Member
    Join Date
    Jan 2003
    Posts
    29

    Connecting to you local machine from a domain.

    If you own you own domain, then you prolly can do what im playing with. Its called a DNS pointer. It allows you to point a subdomain to a different ip then your normal webspace. Hey you could point it to your local machine even

    for example my game could be hosted at my webspace at xmcnuggetx.com, but i could have a dns pointer lets say (myserver.xmcnuggetx.com), and point it to my local machine.

    Flash will allow a movie to connect to a subdomain, even if its a different ip =D *JOY*

    Nugget
    xMCNUGGETx

  18. #18
    Junior Member
    Join Date
    Jan 2003
    Posts
    29

    programming a vb socket server

    http://www.winsockvb.com/article.php?article_id=18

    Tutorial for excepting multiple connections using the winsock control. Wasnt specifically desinged for flash to connect to but it works =)

    Nugget
    xMCNUGGETx

  19. #19
    Member
    Join Date
    Dec 2002
    Posts
    58

    Thanks ED!

    Thanks Ed!
    If you are interested in a postition for making an RPG like Diablo in Flash, contact us at flashrpgprogrammer@yahoo.com

  20. #20
    Member
    Join Date
    Dec 2002
    Posts
    58

    Some Servers...

    Hey Everyone,

    if you want a good server to start with, go with ElectroServer.
    Last edited by rpgprogrammer; 02-07-2003 at 02:14 PM.
    If you are interested in a postition for making an RPG like Diablo in Flash, contact us at flashrpgprogrammer@yahoo.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center