Cannot connect remote server to smartfox with unity3d

369 Views Asked by At

I'm trying to connect smartfoxserver with unity3d. local machine is working fine. But when I've tried on my server ip like xx.xx.xx.xx, given error like follow,

What should I do?

Http error creating http connection: System.Net.Sockets.SocketException: Connection refused
  at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP, Boolean requireSocketPolicy) [0x00000] in <filename unknown>:0 
  at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x00000] in <filename unknown>:0 
  at System.Net.Sockets.TcpClient.Connect (System.Net.IPEndPoint remote_end_point) [0x00000] in <filename unknown>:0 
  at System.Net.Sockets.TcpClient.Connect (System.Net.IPAddress[] ipAddresses, Int32 port) [0x00000] in <filename unknown>:0 
UnityEngine.Debug:Log(Object)
SFS2X_Connect:OnConnection(BaseEvent) (at Assets/SFS2X_Connect.cs:31)
Sfs2X.Core.EventDispatcher:DispatchEvent(BaseEvent)
Sfs2X.SmartFox:ProcessEvents()
SFS2X_Connect:Update() (at Assets/SFS2X_Connect.cs:37)

connection code is shown below

public class SFS2X_Connect : MonoBehaviour {

    public string ServerIP = "xxx.xxx.xxx.xxx";
    public int ServerPort = 9933;

    SmartFox sfs;

    void Start () {
        sfs = new SmartFox ();

        sfs.ThreadSafeMode = true;

        sfs.AddEventListener (SFSEvent.CONNECTION, OnConnection);

        sfs.Connect (ServerIP, ServerPort);

    }

    void OnConnection(BaseEvent evt)
    {
        if ((bool)evt.Params ["success"]) {
            Debug.Log ("Successfully Connected");
        } 
        else {
            Debug.Log ((string)evt.Params["errorMessage"]);
        }
    }

    void Update () {
        sfs.ProcessEvents();

    }

}
1

There are 1 best solutions below

2
Pirisok On BEST ANSWER

Create a ConfigData then pass it to sfs for connection :

    ConfigData cfg = new ConfigData();
    cfg.Host = "x.x.x.x";
    cfg.Port = 9932;
    cfg.Zone = loginZone;
    cfg.Debug = true;
    smartFox.Connect(cfg);