SmartFox 服务器无响应
Posted
技术标签:
【中文标题】SmartFox 服务器无响应【英文标题】:No response from SmartFox Server 【发布时间】:2013-12-17 21:50:32 【问题描述】:我是 smartfox 服务器的新手,并且一直在尝试一些基本代码如何实现它..这是我的代码..我一直在尝试基本添加两个 no。服务器代码的响应.. 这是我的安卓代码...
sfs=new SmartFox();
// tv.setText("Disconnected");
sfs.addEventListener(SFSEvent.LOGIN, new IEventListener()
@Override
public void dispatch(BaseEvent evt) throws SFSException
// TODO Auto-generated method stub
String parms = evt.getArguments().toString();
Log.v("Args", parms);
if(evt.getType().equalsIgnoreCase(SFSEvent.LOGIN))
sfs.send(new JoinRoomRequest("Demo Lobby"));
Log.d("log9", "after sending req to join room");
else
Log.d("log8", "Joining not allowed");
);
sfs.addEventListener(SFSEvent.ROOM_JOIN, new IEventListener()
@Override
public void dispatch(BaseEvent evt) throws SFSException
// TODO Auto-generated method stub
String par=evt.getArguments().toString();
Log.d("rooms", par);
SFSObject sfsobj=new SFSObject();
sfsobj.putInt("n1", 11);
sfsobj.putInt("n2", 13);
sfs.send(new ExtensionRequest("add",sfsobj));
Log.d("log10", "request sent");
);
sfs.addEventListener(SFSEvent.EXTENSION_RESPONSE, new IEventListener()
@Override
public void dispatch(BaseEvent evt) throws SFSException
// TODO Auto-generated method stub
Log.d("log11", "Into Extension Response");
// Map params=arg0.getArguments();
// SFSObject sfso=(SFSObject) params.get("add");
// int i=sfso.getInt("sum");
// Log.d("log11", "req accept");
// Log.d("i value", String.valueOf(i));
//SFSObject o=(SFSObject) arg0.getArguments().get("add");
//String str=arg0.getArguments().toString();
//Log.d("object recieved", str);
// int i=o.getInt("res");
// Log.d("i value", String.valueOf(i));
// System.out.println(i);
//
if(evt.getArguments().get("cmd")=="add")
ISFSObject param=(ISFSObject) evt.getArguments().get("params");
int sum=param.getInt("res");
System.out.println("Summ is:"+sum);
);
sfs.addEventListener(SFSEvent.CONNECTION, new IEventListener()
@Override
public void dispatch(BaseEvent evt) throws SFSException
// TODO Auto-generated method stub
if(evt.getType().equalsIgnoreCase(SFSEvent.CONNECTION))
Log.d("log2", "connected"+sfs.getConnectionMode());
//Toast.makeText(ConnectionActivity.this, "Connected", Toast.LENGTH_LONG).show();
System.out.println("Connection success"+sfs.getConnectionMode());
//tv.setText("Status:Connected");
LoginRequest loginRqst = new LoginRequest(userName, password, zoneName);
sfs.send(loginRqst);
else
Log.d("log3", "connection error"+sfs.getConnectionMode());
//Toast.makeText(ConnectionActivity.this, "Error", Toast.LENGTH_LONG).show();
System.out.println("Connection unsuccess"+sfs.getConnectionMode());
);
btn.setOnClickListener(new OnClickListener()
@Override
public void onClick(View v)
// TODO Auto-generated method stub
Log.d("log1", "bfore connect");
sfs.connect(serverIp,port);
sfs.setUseBlueBox(true);
);
btn1.setOnClickListener(new OnClickListener()
@Override
public void onClick(View v)
// TODO Auto-generated method stub
if(sfs.isConnected())
sfs.disconnect();
Log.d("log4", "Disconnected");
else
Log.d("log5", "The connection was never made");
);
这是我的扩展类..
public class MyClassExtension extends SFSExtension
@Override
public void init()
// TODO Auto-generated method stub
addRequestHandler("add", ClientServerRequest.class);
这是我的处理程序类..
public class ClientServerRequest extends BaseClientRequestHandler
@Override
public void handleClientRequest(User arg0, ISFSObject arg1)
// TODO Auto-generated method stub
int n1 = arg1.getInt("n1");
int n2 = arg1.getInt("n2");
trace(n1,n2);
// Create a response object
ISFSObject resObj = SFSObject.newInstance();
resObj.putInt("res", n1 + n2);
MyClassExtension ext = (MyClassExtension)getParentExtension();
trace("SUM is "+(n1+n2));
// Send it back
ext.send("add", resObj, arg0);
trace("Extension response has been sent");
我尝试了所有方法将结果获取到 EXTENSION_RESPONSE..但无法获得总和..也在区域配置器中..我已正确配置它...请帮助..提前谢谢..
【问题讨论】:
【参考方案1】:让我知道,当您在 SFSadmin 视图中看到时,您是否得到了区域中的计数,n 在这里您提到了 zonename 是否引用了该区域名称,并且您在控制台中是否有任何消息 [使用 sfs2x 运行 SFS。 bat 而不是服务] 任何消息,如客户端 'xxx' 已连接...或没有为客户端发送的“添加”注册请求处理程序..
【讨论】:
是的..我再次重新安装了 SmartFox..没有将其作为服务安装..它确实有效..以上是关于SmartFox 服务器无响应的主要内容,如果未能解决你的问题,请参考以下文章