【发布时间】:2018-01-28 06:28:06
【问题描述】:
我在 Unity3d 上使用 SmartFoxServer API。在我恢复 MacBook 之前它工作正常,但现在出现如下连接错误:
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:2758)
Sfs2X.Core.EventDispatcher:DispatchEvent(BaseEvent)
Sfs2X.SmartFox:ProcessEvents()
SFS2X_Connect:Update() (at Assets/SFS2X_Connect.cs:2764)
这是连接代码:
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
using System.Collections;
using Sfs2X;
using Sfs2X.Core;
public class SFS2X_Connect : MonoBehaviour {
public string Host = "127.0.0.1";
[Tooltip("TCP port listened by the SmartFoxServer 2X instance; used for regular socket connection in all builds except WebGL")]
public int TcpPort = 9933;
[Tooltip("WebSocket port listened by the SmartFoxServer 2X instance; used for in WebGL build only")]
public int WSPort = 8888;
[Tooltip("Name of the SmartFoxServer 2X Zone to join")]
public string Zone = "examplezone";
SmartFox sfs;
sfs = new SmartFox ();
sfs.ThreadSafeMode = false;
sfs.AddEventListener (SFSEvent.CONNECTION, OnConnection);
ConfigData cfg = new ConfigData();
cfg.Host = Host;
cfg.Port = TcpPort;
cfg.Zone = Zone;
sfs.Connect (cfg);
}
我已经删除并重新导入了smartfox.dll,但仍然遇到同样的错误。
我能做什么?
注意:我创建了一个新项目并导入了 SnartFoxServer。它已连接到服务器。
【问题讨论】:
-
如果没有服务监听指定端口,或者有防火墙阻止你,通常套接字连接会被拒绝。你检查过吗?
-
@Smartis 我在问题中添加了更多详细信息
-
您是否已经用localhost:8080 配置了服务器?如果您在终端中输入
./sfs2x-service status会显示什么信息? -
"守护进程正在运行"
-
还有
netstat -p tcp | grep $PORT在终端列表9933 中吗?另外请将sfs的构造函数添加到您的问题中。
标签: c# unity3d smartfoxserver