it crashes on connect(ip, port). If it comment this out, the service starts. The port is good, the ip is good, other clients connect to the server just fine. I changed it from my cloud host to localhost in this code sample. I tried it with ConfigData, still crashed. I'm on Android OS9.
Code: Select all
package com.ronin.connect;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.widget.Toast;
import sfs2x.client.SmartFox;
import sfs2x.client.core.BaseEvent;
import sfs2x.client.core.IEventListener;
import sfs2x.client.core.SFSEvent;
import sfs2x.client.requests.JoinRoomRequest;
import sfs2x.client.requests.LoginRequest;
import sfs2x.client.util.ConfigData;
public class MyService extends Service implements IEventListener {
int mStartMode;
IBinder Binder;
boolean mAllowRebind;
SmartFox sfsClient;
//ConfigData cfg = new ConfigData();
@Override
public void onCreate() {
// The service is being created
initSmartFox();
}
private void initSmartFox() {
// Instantiate SmartFox client
sfsClient = new SmartFox();
// Add event listeners
sfsClient.addEventListener(SFSEvent.CONNECTION, this);
sfsClient.addEventListener(SFSEvent.CONNECTION_LOST, this);
sfsClient.addEventListener(SFSEvent.LOGIN, this);
sfsClient.addEventListener(SFSEvent.ROOM_JOIN, this);
Toast.makeText(getApplicationContext(),"Connecting",Toast.LENGTH_SHORT).show();
// CRASHING RIGHT HERE
sfsClient.connect("10.1.1.10", 9933);
}
@Override
public void dispatch(final BaseEvent event) {
if (event.getType().equalsIgnoreCase(SFSEvent.CONNECTION)) {
if (event.getArguments().get("success").equals(true)) {
// login to current zone
// sfsClient.send(new LoginRequest("test", "test"));
} else {
// failed connection
}
} else if (event.getType().equalsIgnoreCase(SFSEvent.CONNECTION_LOST)) {
disconnect();
} else if (event.getType().equalsIgnoreCase(SFSEvent.LOGIN)) {
sfsClient.send(new JoinRoomRequest("1"));
} else if (event.getType().equalsIgnoreCase(SFSEvent.ROOM_JOIN)) {
// room join code
}
}
private void disconnect() {
if (sfsClient.isConnected()) {
sfsClient.disconnect();
}
}
public void onStartService(Intent intent, int startId) {
// TODO Auto-generated method stub
Toast.makeText(this, "Connector Started", Toast.LENGTH_LONG).show();
super.onStart(intent, startId);
}
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean onUnbind(Intent intent) {
// All clients have unbound with unbindService()
return mAllowRebind;
}
@Override
public void onRebind(Intent intent) {
// A client is binding to the service with bindService(),
// after onUnbind() has already been called
}
@Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
Toast.makeText(this, "Connector Stopped", Toast.LENGTH_LONG).show();
}
}