I use SFS_PRO(1.6.6) and Unity (4.0.1)
Server IP is 140.128.80.150 (at school)
gateway is 140.128.80.254
Client code using C#:
Code: Select all
public class LoginGUI : MonoBehaviour {
private SmartFoxClient sfc;
public string serverIP = "140.128.80.150";
public int serverPort = 9339;
public string zone = "city";
public bool debug = true;
private string username = "charles";
private string password = "123456789";
private string loginErrorMessage = "";
/************
* Unity callback methods
************/
void OnApplicationQuit() {
try{sfc.Logout();
sfc.Disconnect();
}catch{}
}
void Awake() {
Application.runInBackground = true;
if ( SmartFox.IsInitialized() ) {
sfc = SmartFox.Connection;
} else {
try {
sfc = new SmartFoxClient(debug);
sfc.runInQueueMode=true;
} catch ( Exception e ) {
loginErrorMessage = e.ToString();
}
}
// Register callback delegate
SFSEvent.onConnection += OnConnection;
SFSEvent.onConnectionLost += OnConnectionLost;
SFSEvent.onExtensionResponse += OnExtensionResponse;
SFSEvent.onRoomListUpdate += OnRoomList;
SFSEvent.onLogin+=OnLogin;
SFSEvent.onDebugMessage += OnDebugMessage;
sfc.Connect(serverIP, serverPort);
}
void FixedUpdate() {
sfc.ProcessEventQueue();
}
void OnGUI() {
try{
if ( sfc.IsConnected() ) {
// Login
float centerX=Screen.width/2;
float centerY=Screen.height/2;
GUI.Box(new Rect(centerX-150,centerY-100,300,200),"");
GUI.Label(new Rect(centerX-100, centerY-50, 100, 100), "Userame: ");
username = GUI.TextField(new Rect(centerX-20,centerY-50, 150, 20), username, 25);
GUI.Label(new Rect(centerX-100,centerY, 100, 100), "Password: ");
password = GUI.PasswordField(new Rect(centerX-20,centerY, 150, 20), password, '*',16);
GUI.Label(new Rect(10, 130, 100, 100), loginErrorMessage);
if ( GUI.Button(new Rect(centerX-50, centerY+50, 100, 30), "Login") ) {
sfc.Login(zone, username, password);
}
} else {
GUI.Label(new Rect(10, 100, 100, 100), "Waiting for connection");
GUI.Label(new Rect(10, 130, 100, 100), loginErrorMessage);
if(GUI.Button (new Rect(10,200,100,30),"reconnect"))
{sfc.Connect(serverIP, serverPort);
loginErrorMessage="";
}
}
}catch{
sfc.Disconnect();
Application.Quit();
}
if(sfc.myUserId!=-1)
Application.LoadLevel("Lobby");
}
but, I tried to use AdminTool to connect , It is work!
Why? Please someone Can me?
If I lost trails ,I will supply soon.