views:

1814

answers:

4

I'm interested in putting together my first online game using Flash as the client and writing a back-end application in C++ where the actual game state is kept.

I've done lots of games in C++ before using SDL, SFML, Allegro, etc etc but never gotten around to using the network libraries. I was just interested in some helpful direction for which libraries are best suited to game servers where the actual server doesn't have any graphical display (or doesn't need to but could have). In all honesty I think the answer will be any and once I get the hang of sockets it'll become a breeze sending data back and forth... but it can't help to ask first.

I have very little experience in flash or as3 but like the idea of being able to access the game through a browser - learning flash is obvisouly going to be an obstical that I'll have to overcome but my main interest again is any tips on libraries, or sources, or tutorials that are good for sending/recieving data via sockets or whichever method works best.

I've read about the arguments between TCP/UDP so I don't want to start a war like that here; just general helpful advice please - I'm only looking for something simple to get me up and running :-p

As a side note, the reason I'm choosing C++ is because the players are actually robots with minature virtual-machines and everything will run on the server so as the player count rises so will the need to emulate each and every vm :-p

Update:

The game world is intended to be real-time, but the interaction of the player doesn't have to be. The basis of the game is that you program little robots that interact in a persistent world and have goals and challenges to meet on a daily/weekly basis to earn points.

I was thinking that buffering the display data would be possible as the player doesn't need real-time visual as they have no direct control of their robots. The server would buffer up 10 seconds or so of data for each connection and then ship it out in one go - this way while the data is being played back in the client the server is busy buffering some more.

The general interactions the player will have with the server will be uploading new code and getting statistics, there may also be other one off commands to move your robot around or reset it to a starting position. Any remote control is done through a communications channel and thus is delayed by the buffer. This could easily be explained by the fact that the persistent world is somewhere like Mars (the planet) and the signal takes a while to go back and forth.

I was planning on having a "lab" whereby you could set up the robots and test them in realtime on the client, this has nothing to do with the actual game world and thus shouldn't require any networking - although I don't fancy writing a VM in both languages :(

I'm completely comfortable in C++ and have some working prototypes of the persistent world in place already - I'm just a complete newbie when it comes to networking so figured it'd be best to get advice first.

+2  A: 

Although it's primarily written for C, it's still great for C++:
Beej's guide to networ programming.k
It covers all the basics, and has a section on changes needed for Win32 :)
Also I seem to recall that Flash needed terminating null-bytes on each packet, so instead of send(socket,szData,strlen(szData),0); use send(socket,szData,strlen(szData)+1,0); to send a string :)

Frans-Willem
+2  A: 

Use boost::asio for network programming

A: 

I'm not sure if your game needs real time communications or if if making requests to a server to load, save and execute games is sufficient.

If it is you might be best to use some kind of "middleware" layer to handle the networking parts. Flash is happy making xml documents and sending them to a server over HTTP and then processing received XML responses. it has a lot of good built in stuff to handle all of those things in a very easy way.

Perhaps you could have a server in c# or php or java depending on your platform which runs in a webserver and handles the requests and responses and passes on requests to your c++ server which could run independently on a server via a message queue or database or local connection.

It might be easier on both the flash and server sides to handle the networking and communications issues in this way as c++ isn't the easiest language to do networking in even with a library.

I don't know if this meets your requierments either for your game or platform though, I'm just throwing it in as a suggestion

John Burton
+1  A: 

When using Flash's Socket or XMLSocket classes, make sure you have a security policy file on your server. otherwise, you will not be able to open a socket. Check out this SO question for more info.

zooropa
............ +1 !
Poni