Page 1 of 1

SFS.Connection problem in first example

Posted: 30 May 2011, 19:44
by shaka
Hi! I'm just starting out in smartfoxserver and I've run into a problem while following the example in the youtube tutorial for creating a flash application. I tried searching but couldn't find anything, so apologies if this was answered already.

Problem: My code compiles correctly without any errors or warnings, but my onConnection function never triggers (is something wrong with my event listener?).


Main.mxml:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx"
			   initialize="init()">
	
	<fx:Declarations>
		<!-- Place non-visual elements (e.g., services, value objects) here -->
	</fx:Declarations>
	
	<fx:Script>
		<![CDATA[
		import com.smartfoxserver.v2.core.SFSBuddyEvent;
		import com.smartfoxserver.v2.entities.Room;
		import com.smartfoxserver.v2.entities.User;
		import com.smartfoxserver.v2.requests.JoinRoomRequest;
		import com.smartfoxserver.v2.requests.LoginRequest;
		import com.smartfoxserver.v2.requests.PublicMessageRequest;
		import com.smartfoxserver.v2.SmartFox;
		import com.smartfoxserver.v2.core.SFSEvent;
		import flash.events.Event;
		
		private var _sfs:SmartFox;
		
		private function init():void
		{
			
			_sfs = new SmartFox(true);
			_sfs.addEventListener(SFSEvent.CONNECTION, onConnection);
			_sfs.addEventListener(SFSEvent.LOGIN, onLogin);
			_sfs.addEventListener(SFSEvent.ROOM_JOIN, onRoomJoin);
			_sfs.addEventListener(SFSEvent.PUBLIC_MESSAGE, onPublicMessage);
			chatLog.text += 'Initializing...\n';
		}
		
		protected function login_clickHandler(event:MouseEvent):void
		{
			
			_sfs.loadConfig('config.xml');
			chatLog.text += 'Loaded Config.\n';
		}
		
		private function onConnection(event:SFSEvent):void
		{
			if(event.params.success)
			{
				chatLog.text += 'Connection Success~~!!\n';
				var request:LoginRequest = new LoginRequest('');
				_sfs.send(request);
			}
			else
			{
				chatLog.text += 'Connection Failed...\n';
			}
		}
		
		private function onLogin(event:SFSEvent):void
		{
			chatLog.text += 'Login Success!!\n';
			var request:JoinRoomRequest = new JoinRoomRequest('Da Lobby');
			_sfs.send(request);
		}
		
		private function onRoomJoin(event:SFSEvent):void
		{
			var room:Room = event.params.room;
			chatLog.text += 'Joined Room: ' + room.name+ '\n';
		}
		
		
		private function onPublicMessage(event:SFSEvent):void
		{
			var user:User = event.params.sender;
			chatLog.text += user.name + ": " + event.params.message + '\n';
		}
		
		protected function chat_clickHandler(event:MouseEvent):void
		{
			if (chatInput.text.length > 0)
			{
				var request:PublicMessageRequest = new PublicMessageRequest(chatInput.text);
				_sfs.send(request);
				chatInput.text = '';
			}
		}
		
		protected function chatgarbage(event:MouseEvent):void
		{
			chatLog.text += 'lahbkshlkhs!!';
			chatInput.text = '';
		}
		
		]]>
		
	</fx:Script>
	
	<s:Panel width="350" height="290" title="MyChat" horizontalCenter="0" verticalCenter="0">
		<s:Button id="login" label="Login" x="10" y="10" click="login_clickHandler(event)"/>
		<s:Button id="testchat" label="output and clear" x="150" y="10" click="chatgarbage(event)"/>
		<s:TextArea id="chatLog" x="10" y="39" width="330" height="171"/>
		<s:TextInput id="chatInput" x="10" y="220" width="250"/>
		<s:Button id="chat" label="Chat!" x="268" y="221" click="chat_clickHandler(event)"/>
	</s:Panel>
	
	
</s:Application>
config.xml

Code: Select all

<SmartFoxConfig>
	<!-- Mandatory Settings -->
	<ip>127.0.0.1</ip>
	<port>9933</port>
	<zone>MyNUZone</zone>
	
	<debug>true</debug>
	
	<!---- For Generic http port comm. -->
	<httpPort>8080</httpPort>
	
	<udpIp>127.0.0.1</udpIp>
	<udpPort>5152</udpPort>
</SmartFoxConfig>
Thanks in advance!

SFS.Connection problem in first example

Posted: 31 May 2011, 11:25
by forsfs09
Hi,

Check if the service of sfs server is running. If yes then check for config file
load events ie...

_sfs.addEventListener(SFSEvent.CONFIG_LOAD_FAILURE, onConfigLoadFailure);
_sfs.addEventListener(SFSEvent.CONFIG_LOAD_SUCCESS,onConfigLoadSuccess);

If you get load success then server is responding fine that is service is
running at back end..

Regards

Re: SFS.Connection problem in first example

Posted: 02 Jun 2011, 19:55
by shaka
forsfs09 wrote:Hi,

Check if the service of sfs server is running. If yes then check for config file
load events ie...

_sfs.addEventListener(SFSEvent.CONFIG_LOAD_FAILURE, onConfigLoadFailure);
_sfs.addEventListener(SFSEvent.CONFIG_LOAD_SUCCESS,onConfigLoadSuccess);

If you get load success then server is responding fine that is service is
running at back end..

Regards
Thanks for the response!

I checked both Services and the SFS Admin panel to see if it was running - it said it was (IP and Port also are correct, 127.0.0.1:9933). However, I'm still getting failures when trying to load the config. Even when I try to build it and/or put the building file in the SFS www/root folder, config still fails. Any suggestions on what to do?

Thanks for your help!

Posted: 12 Jun 2011, 03:00
by shaka
Can anyone help me with this config file problem? I've tried building the examples (like Advanced Chat, Game Lobby) and everything works except the loading config part.

I haven't modified the server address (127.0.0.1:9933) and according to the admin panel, the zone I'm trying to enter exists. Can anyone please help me?

Posted: 13 Jun 2011, 06:21
by heovespa
@shaka: show your log file :D