我正在尝试将 smartfoxserver 与 unity3d 连接。本地机器工作正常。但是当我尝试像 xx.xx.xx.xx 这样的服务器 ip 时,给出如下错误,
我应该怎么办?
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)
连接代码如下图
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();
}
}