AIR server connections

104 views Asked by At

I am wanting to give back to a small gaming community. The idea is to make an app that acts like a chat client to connect to the game servers. I am trying to grasp the concepts on how connections work through examples I've found on the web, since I am self taught by seeing examples.

So far the examples I found are for connections on the same network. What I need is some kind of example that will allow me to connect from different networks or at least an explanation on what I need to do. Also I need to be able to get around a router without with setting port forwarding on the router.

In the end the app will be connecting to the game developer's server but I need a working app before I get his permission to connect to his servers.

Any help will be most appreciated. If any additional information is needed to help just ask and I'll do my best to fill in the gaps.

1

There are 1 answers

0
Colonize.bat On BEST ANSWER

That is a very broad question, but I try to give you as much information as possible from by point of view. As I'm not yet sure if you want to have a P2P Connection (game-application to game-application) or a standard server model, I will just mentioned different approaches to this problem.

Adobe has support for P2P since a long time. Read some FAQ, esspecially "How does RTMFP differ from RTMP?" (I try to choose Sources with infographics, as that helped me to understand it).

What you really should start playing with and making first steps in, should be NetConnection. This is the very basic Function that will allow you to communicate to a Server running e.g. PHP or connecting to a Flash Media Server (FMS). FMS is inpartcular interresting for you, as it really boosts the ideas what you game could do, but setting up a FMS is not that easy,to host a own instance is even more complex. So if you come to the conclusion that you want to travel the road of using a FMS, I can suggest you Onyx Server. They mainly marketing theirself as a Streaming service, but in reality you will get access to a FMS for a ok'ish price (FMS instances on Amazon were way worst the last time I checked). The FMS basicly only a Flash AS2 File with some extra Commands. Your FMS can handle real-time (!) persistent connections (!) with any client that connects to it. Everyone is able to connect to the server at first, and you can then choose in your FMS Script what a client have to bring to the table to stay on the server or is rejected. After that, you have a very string tool for a Game. For example, you could have a game instance connect to it, tell the server that an enemy was hit and the server near-instantly (the speed is really amazing, there is no feeled delay, it really is instant. Its called SharedObjects) pass this information down to the enemy game instance. I used FMS only for one project and it was a very long ride to understand it and work with it, but it was a really nice experience, as you code the Server in the "same" language like the game itself (AS2, AS3 = ECMA).

If you dont want to spend money at this stage, you can use the Adobe RTMFP Instance at p2p.rtmfp.net. It is, as far as I know, only for testing and you will be rejected if you misuse the service for a real project, but for starting and testing it will do. If you use the Cirrus Engine, you can even follow this Tutorial. You will find sample code in there:

// Cirrus connect info 
private const SERVER:String = "rtmfp://p2p.rtmfp.net/"; 
private const DEVKEY:String = "{YOUR_DEVELOPER_KEY}"; 

// Used to connect to the Cirrus service
private var _netConnection:NetConnection; 

_netConnection = new NetConnection(); 

// Listen for status info 
_netConnection.addEventListener( NetStatusEvent.NET_STATUS, onNetStatus ); 

// Connect to Cirrus using our unique URI 
_netConnection.connect( SERVER + DEVKEY );

My adive for you would be: Try getting comfortable with NetConnection. It is really straight forward. When I first started using it, I had a couple of days struggeling and reading a lot on the web, but I learned a lot doing so. You should too. Use NetConnection and try to create two simple AS3/FLA instances of your code that both connect to the same domain (use the adobe rtmfp domain for now) and try to exchange some simple String-Data between these instances.

To take some of the pain of your shoulders, add the minimum amount of listeners to your NetConnection like so:

//Main NetConnector
nc = new NetConnection();

//Troubleshooting Listener
nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
nc.addEventListener(NetStatusEvent.NET_STATUS, status_handler);
//nc.objectEncoding = ObjectEncoding.AMF0; //Default
nc.client = this;
nc.connect("https://some-domain");

////////////////////////////////////////////////////////////////////////////////
/// CALL ERROR LISTENER
////////////////////////////////////////////////////////////////////////////////

private function status_handler(e:NetStatusEvent):void {
    //trace("NetStatusEvent");
    dispatchEvent(new CallEvent(CallEvent.CALL_NATIVE_NET_STATUS, e, true ));

}

private function securityErrorHandler(e:SecurityErrorEvent):void {
    //trace("SecurityErrorEvent");
    dispatchEvent(new CallEvent(CallEvent.CALL_NATIVE_SECURITY_ERROR, e, true ));

}

You will get alot of errors and netStatus and NetSecuriy Events. Flash will often run into Sandbox-Violation errors when you now know what you are doing. That can be frustrating but if you keep it up, google every error and compare you implementations with the implementation of others, you will wrap your head around this and can do really neat stuff with it.

I recommend you google sources and tutorials for NetConnection and stick to one that is on your level of knowledge.

Good Luck.