简体   繁体   中英

Cannot connect remote server to smartfox with unity3d

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();

    }

}

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM