Recently i wrote in "Java client API" topic about my problem. I'd like to thank everybody who answered me there, but none of offered in that topic decisions have helped. So i decided to create separate topic to describe my problem in details.
It's my first experience with SmartFoxServer. I downloaded it (i work under Ubuntu 10.04), unzipped, and ran (exactly as in documentation). I can connect to admin tool, i can run flash examples from localhost:8080 page (SimpleChat, SFSTris, etc.). I can connect to admin tool and run examples from remote computer. Everything seems to be ok. Even Unity3D FPS Demo works excellent.
Then i tried to write my Java client. I looked up in Java SimpleChat example how to create SmartFoxClient object, how to add event listeners, etc.
That's my application source code:
Code: Select all
package main;
public class ClientSFSMain {
public static void main(String[] args)
{
Controller controller = new Controller();
controller.initialize();
}
}
Code: Select all
package main;
import it.gotoandplay.smartfoxclient.ISFSEventListener;
import it.gotoandplay.smartfoxclient.SFSEvent;
import it.gotoandplay.smartfoxclient.SmartFoxClient;
import java.util.logging.Level;
public class Controller implements ISFSEventListener {
private SmartFoxClient sfs;
public void initialize()
{
sfs = new SmartFoxClient(true);
sfs.addEventListener(SFSEvent.onConfigLoadSuccess, this);
sfs.addEventListener(SFSEvent.onConfigLoadFailure, this);
sfs.addEventListener(SFSEvent.onConnection, this);
sfs.addEventListener(SFSEvent.onConnectionLost, this);
sfs.addEventListener(SFSEvent.onDebugMessage, this);
sfs.getLogger().setLevel(Level.ALL);
log("controller created");
sfs.loadConfig("config.xml", false);
}
@Override
public void handleEvent(SFSEvent event)
{
if(event.getName().equals(SFSEvent.onDebugMessage))
{
log(event.getParams().toString());
}
else if(event.getName().equals(SFSEvent.onConfigLoadSuccess))
{
log("config loaded");
sfs.defaultZone = "SimpleChat";
sfs.connect(sfs.ipAddress, sfs.port);
}
else if(event.getName().equals(SFSEvent.onConfigLoadFailure))
{
log("config load error");
}
else if(event.getName().equals(SFSEvent.onConnection))
{
log("onConnection");
if(event.getParams().getBool("success"))
{
log("connected");
}
else
{
log("not connected");
System.exit(-2);
}
}
else if(event.getName().equals(SFSEvent.onConnectionLost))
{
log("connection lost");
System.exit(-1);
}
}
private void log(String str)
{
System.out.println(str);
}
}
Code: Select all
<SmartJChatConfig>
<ip>127.0.0.1</ip>
<udpIp>127.0.0.1</udpIp>
<port>9933</port>
<udpPort>9933</udpPort>
<zone>SimpleChat</zone>
<debug>true</debug>
<httpPort>8080</httpPort>
<useBlueBox>true</useBlueBox>
<blueBoxPollingRate></blueBoxPollingRate>
</SmartJChatConfig>
java.io.FileNotFoundException: /xml/dtds/cross-domain-policy.dtd (No such file or directory)
If i change crossdomain.xml file (replace string after SYSTEM to "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd"), application won't throw exception. But it cannot connect to server.
In console i see, that controller created, config loaded. After this there are many messages
Mar 1, 2011 1:20:30 PM it.gotoandplay.smartfoxclient.SmartFoxClient debugMessage
INFO: [ RECEIVED ]: , (len: 0)
{ "message" : "[ RECEIVED ]: , (len: 0)" }
and then "connection lost" string appears.
Can you help?