Smartfox Server-Chapter 02-Connection with Server

October 1st, 2010 by aabhaanjan

Establish connection with server

To make connection between server and client we need three most important parts :

IP : IP of system where smartfox is Installed.

Port : Port number by default it is 9339.

Zone : name of zone where you want to make the connection.

At first I would like to suggest you to make a config.xml file which will have above three essential parts in the form of their node. Now the first question will come in your mind why XML when we can declare it inside the action script code ? So answer is it will make your life easy. During the various stages of development you will need to change the IP at that time it will be easy to modify it from outside. Therefore here I have used the same way and created this config.xml.

1

Now what we need to do with Action script to establish the connection? Create a screen with a dynamic text box where we will show the status of connection.

2

Now create a document class : Paste following codes :

34

In above code we are importing the packages of smartfox then we are calling two smartfox event “onConnectToSFS” and “onConnectionLost” which will show the status of connection. Now by using “LoadConfigData” function we are loading the config.xml. On config loaded we are getting the IP,Port and zone by using this we are calling the function connectToSfs where we are sending request for connection to the server. If connection will succeed the text box will show the message “Connected”. On connection loss the text box will show the message “Disconnected”.

5

Now lets move to the next chapter where we will discuss detail about the config structure . We will discuss what is the meaning of other nodes of above structure.

Previous Chapter :                                                                                                                                                                                            Next Chapter :

Tags: , , , , , , , , , , , , , , , , , , , ,